Android XML调整大小/调整图像按钮不同屏幕
我做了ImageButton菜单设计,希望它的大小可以调整屏幕: 但在我测试使用智能手机3英寸320x480后 ,4英寸480x800,5英寸720x1280,查看图像按钮乱七八糟 我试过使用TableLayout,LinearLayout,GridLayout, 和FrameLayout,但结果是相同的 先谢谢你 这是我的XML代码:Android XML调整大小/调整图像按钮不同屏幕,android,xml,imagebutton,screens,Android,Xml,Imagebutton,Screens,我做了ImageButton菜单设计,希望它的大小可以调整屏幕: 但在我测试使用智能手机3英寸320x480后 ,4英寸480x800,5英寸720x1280,查看图像按钮乱七八糟 我试过使用TableLayout,LinearLayout,GridLayout, 和FrameLayout,但结果是相同的 先谢谢你 这是我的XML代码: 我创建了一个scratch,它将用线性和权重定义布局 我希望它能帮助你 还附带了带有屏幕截图的代码 Plz提供更清晰的布局,您需要制作不同大小的图像:您需
我创建了一个scratch,它将用线性和权重定义布局 我希望它能帮助你 还附带了带有屏幕截图的代码
Plz提供更清晰的布局,您需要制作不同大小的图像:您需要专门使用百分比法对其进行计算/您需要添加不同分辨率的图像,以便在屏幕上显示适当大小的图像。如果您使用的是android studio,那么您可以尝试使用诸如Batch drawable import之类的插件,在应用程序中添加不同密度的图像。另一个选项是添加svg并为图像按钮指定宽度和高度。@Mohit Trivedi感谢您的评论。我使用RelativeLayout,这是我的xml代码。请更正嗨,谢谢你的回答,我会试试的。请看我的xml代码screenshot@MohitTrivedi:那是什么软件?:)在笔记本中&从中捕获camera@Johan在这里,我做了一个布局参考它,并告诉我,如果你需要任何问题&它将在任何设备上工作,即使在景观also@MohitTrivedi非常感谢您的帮助,我已经在smarthpone 3英寸、4英寸、5英寸的模拟器中尝试了您的xml代码,其大小和结果都非常令人满意-抱歉,我想再次询问:我是否应该将图像大小设置为不同大小的ImageButton src(可绘制hdpi、可绘制ldpi、可绘制mdpi、可绘制xdpi、可绘制xxdpi),或者仅设置为可绘制hdpi。-理想尺寸是多少,像这个还是什么?可拉伸hdpi(72 x 72)可拉伸ldpi(36 x 36)可拉伸mdpi(48 x 48)可拉伸xhdpi(96 x 96)可拉伸xxhdpi(144 x 144)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg"
android:orientation="vertical"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/linear1">
<ImageView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:src="@drawable/title"
android:contentDescription="title"/>
</LinearLayout>
<ImageButton
android:id="@+id/imagebutton0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/linear1"
android:layout_centerHorizontal="true"
android:scaleType="fitXY"
android:background="@drawable/image"
android:tag="0"
tools:ignore="contentDescription" />
<ImageButton
android:id="@+id/imagebutton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imagebutton0"
android:layout_toLeftOf="@+id/imagebutton4"
android:scaleType="fitXY"
android:background="@drawable/image"
android:tag="2"
tools:ignore="contentDescription" />
<ImageButton
android:id="@+id/imagebutton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imagebutton0"
android:layout_centerHorizontal="true"
android:scaleType="fitXY"
android:background="@drawable/image"
android:tag="4"
tools:ignore="contentDescription" />
<ImageButton
android:id="@+id/imagebutton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imagebutton0"
android:layout_toRightOf="@+id/imagebutton4"
android:scaleType="fitXY"
android:background="@drawable/image"
android:tag="3"
tools:ignore="contentDescription" />
<ImageButton
android:id="@+id/imagebutton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imagebutton4"
android:layout_centerHorizontal="true"
android:scaleType="fitXY"
android:background="@drawable/image"
android:tag="1"
tools:ignore="contentDescription" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal|center_vertical"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:id="@+id/linear2"
android:layout_below="@+id/imagebutton1">
<TextView
android:id="@+id/ib1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:drawableTop="@drawable/ib1"
android:gravity="center"
android:text=""
android:scaleType="fitXY"/>
<TextView
android:id="@+id/ib2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:drawableTop="@drawable/ib2"
android:gravity="center"
android:text=""
android:scaleType="fitXY"/>
<TextView
android:id="@+id/ib3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:drawableTop="@drawable/ib3"
android:gravity="center"
android:text=""
android:scaleType="fitXY"/>
<TextView
android:id="@+id/ib4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:drawableTop="@drawable/ib4"
android:gravity="center"
android:text=""
android:scaleType="fitXY"/>
</LinearLayout>
</RelativeLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.4"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitCenter"
android:src="@mipmap/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@mipmap/ic_launcher" />
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@mipmap/ic_launcher" />
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@mipmap/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.1"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@mipmap/ic_launcher" />
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@mipmap/ic_launcher" />
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@mipmap/ic_launcher" />
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@mipmap/ic_launcher" />
</LinearLayout>
</LinearLayout>