就是一个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)
将登录界面的像素调小写就不报错了
我想问一下这种问题应该怎么处理,图片的像素设成多少比较合适?
典型的drawable文件夹带来的问题,建议是UI只出一套高清无码大图放在xxh-dpi文件夹中,当在分辨率低的手机上运行时,会自动按照比例加载图片,不会出现OOM的问题。直接放在drawable下,默认是适配低分辨率,手机为高分辨率时,会按比例放大,OOM没得商量的。
你这是放在哪个drawable 文件夹下,这个尺寸有点怪异。
建议放到 deawable-xxhdpi 文件夹
就是drawable文件夹的问题,drawable目录下的图片会根据xdpi,xxdpi之类的级别进行比例调整,如果放在drawable下好像是最低级别。
换句话说,如果你手机是1920x1080,实际图片尺寸至少是你图片的三倍。
http://blog.csdn.net/guolin_b...郭霖大神详细解释过