就是一个APP,引导页写了三个layout,分别放了三张图片
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/guideimg1"
/>
</RelativeLayout>
第一次启动的时候显示引导页,然后在进入登录的页面,登录的界面也设置了一张背景图
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:weightSum="1"
android:background="@drawable/login_background">
<Button
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="微信登录"
android:textColor="#fff"
android:textSize="23dp"
android:id="@+id/login_btn"
android:drawableLeft="@mipmap/ic_wechat"
android:drawablePadding="-95dp"
android:paddingLeft="95dp"
android:background="@drawable/button_style_login"
android:layout_gravity="center_horizontal"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="15dp"
android:elevation="21dp" />
</RelativeLayout>
但如果背景图的像素设成750*1344,然后到登录界面程序就崩了,内存溢出的错
java.lang.OutOfMemoryError
android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
android.graphics.BitmapFactory.decodeStream(BitmapFactory.java)
android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java)
android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java)
android.content.res.Resources.loadDrawable(Resources.java)
android.content.res.Resources.getDrawable(Resources.java)
android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:346)
android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:197)
android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:185)
android.support.v7.content.res.AppCompatResources.getDrawable(AppCompatResources.java:100)
android.support.v7.view.menu.MenuItemImpl.getIcon(MenuItemImpl.java:421)
android.support.design.internal.NavigationMenuItemView.initialize(NavigationMenuItemView.java:113)
android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.onBindViewHolder(NavigationMenuPresenter.java:415)
android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.onBindViewHolder(NavigationMenuPresenter.java:338)
android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:5825)
android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:5858)
android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5094)
android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4970)
android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2029)
android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1414)
android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1377)
android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:578)
android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3315)
android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3124)
android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3568)
android.view.View.layout(View.java)
android.view.ViewGroup.layout(ViewGroup.java)
android.widget.FrameLayout.layoutChildren(FrameLayout.java)
android.widget.FrameLayout.onLayout(FrameLayout.java)
android.view.View.layout(View.java)
android.view.ViewGroup.layout(ViewGroup.java)
android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1221)
android.view.View.layout(View.java)
android.view.ViewGroup.layout(ViewGroup.java)
android.widget.FrameLayout.layoutChildren(FrameLayout.java)
android.widget.FrameLayout.onLayout(FrameLayout.java)
android.view.View.layout(View.java)
android.view.ViewGroup.layout(ViewGroup.java)
android.widget.LinearLayout.setChildFrame(LinearLayout.java)
android.widget.LinearLayout.layoutVertical(LinearLayout.java)
android.widget.LinearLayout.onLayout(LinearLayout.java)
android.view.View.layout(View.java)
android.view.ViewGroup.layout(ViewGroup.java)
android.widget.FrameLayout.layoutChildren(FrameLayout.java)
android.widget.FrameLayout.onLayout(FrameLayout.java)
android.view.View.layout(View.java)
android.view.ViewGroup.layout(ViewGroup.java)
android.widget.LinearLayout.setChildFrame(LinearLayout.java)
android.widget.LinearLayout.layoutVertical(LinearLayout.java)
android.widget.LinearLayout.onLayout(LinearLayout.java)
将登录界面的像素调小写就不报错了
我想问一下这种问题应该怎么处理,图片的像素设成多少比较合适?
PHP中文网2017-04-18 09:08:33
드로어블 폴더로 인해 발생하는 일반적인 문제 UI에서는 고화질 무수정 대형 사진 세트만 제작하여 xxh-dpi 폴더에 넣는 것을 권장합니다. 비율에 따라 자동으로 로드됩니다. OOM 문제는 없습니다. Drawable 바로 아래에 배치하면 기본값은 저해상도에 적응하는 것입니다. 휴대폰이 고해상도인 경우 비례하여 확대되며 OOM은 협상할 수 없습니다.
大家讲道理2017-04-18 09:08:33
drawable 폴더의 문제입니다. drawable 디렉터리에 있는 그림이 xdpi, xxdpi 등의 수준에 따라 비례적으로 조정됩니다. drawable 아래에 배치하면 가장 낮은 수준에 있는 것 같습니다.
즉, 휴대폰이 1920x1080인 경우 실제 이미지 크기는 이미지 크기의 최소 3배가 됩니다.