就是一个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
Typical problems caused by drawable folders. It is recommended that the UI only produces a set of high-definition uncensored large pictures and put them in the xxh-dpi folder. When running on a mobile phone with a low resolution, the pictures will be automatically loaded according to the proportion. OOM problem occurs. Place it directly under the drawable, and the default is to adapt to low resolution. When the mobile phone is high resolution, it will be enlarged proportionally, and OOM is not negotiable.
PHP中文网2017-04-18 09:08:33
Which drawable folder do you put it in? The size is a bit weird.
It is recommended to put it in the deawable-xxhdpi folder
大家讲道理2017-04-18 09:08:33
It’s a problem with the drawable folder. The pictures in the drawable directory will be proportionally adjusted according to xdpi, xxdpi and other levels. If they are placed under drawable, they seem to be the lowest level.
In other words, if your phone is 1920x1080, the actual picture size will be at least three times the size of your picture.