Android 固定大小的按钮显示方式不同
我是安卓的新手,我尝试在屏幕上填充4个按钮,我制作了3个不同的布局文件夹布局正常、布局大和布局大。对于普通,我将宽度和高度都设置为120dp,对于xlarge,我将它们都设置为170dp,从而生成一个方形按钮。我在我的LG-E975上测试过,很好,我在三星Galaxy tab 10.0上测试过,也很好,但后来我为其他设备创建了一些模拟器进行测试,结果很糟糕,第四个按钮不在屏幕上,模拟器只显示了3个按钮Android 固定大小的按钮显示方式不同,android,android-layout,android-screen-support,android-screen,Android,Android Layout,Android Screen Support,Android Screen,我是安卓的新手,我尝试在屏幕上填充4个按钮,我制作了3个不同的布局文件夹布局正常、布局大和布局大。对于普通,我将宽度和高度都设置为120dp,对于xlarge,我将它们都设置为170dp,从而生成一个方形按钮。我在我的LG-E975上测试过,很好,我在三星Galaxy tab 10.0上测试过,也很好,但后来我为其他设备创建了一些模拟器进行测试,结果很糟糕,第四个按钮不在屏幕上,模拟器只显示了3个按钮 Emulator info: target: Android 4.2.2 Sk
Emulator info:
target: Android 4.2.2
Skin: 320 x 480
hw.lcd.density: 160
我的LG和emulator都被认为是正常的屏幕大小。
我知道有很多关于这件事的文章,但如果有人能以一种简单易懂的方式向我解释,我将不胜感激。我应该使用固定尺寸的按钮吗
编辑:这是我的普通布局xml
<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.kaw.mp2.MainActivity"
android:background="@color/background_all" >
<Button
android:id="@+id/btn_main_aboutus"
android:layout_width="120dp"
android:layout_height="120dp"
android:text="@string/btn_aboutus_text"
android:layout_centerHorizontal="true"
android:layout_alignParentRight="true"
android:layout_marginTop="20dp"
android:background="@color/background_btn"
android:textColor="@color/text_color_btn" />
<Button
android:id="@+id/btn_main_contactus"
android:layout_width="120dp"
android:layout_height="120dp"
android:text="@string/btn_contactus_text"
android:layout_below="@id/btn_main_aboutus"
android:layout_marginTop="10dp"
android:layout_alignParentRight="true"
android:background="@color/background_btn"
android:textColor="@color/text_color_btn" />
<Button
android:id="@+id/btn_main_products"
android:layout_width="120dp"
android:layout_height="120dp"
android:text="@string/btn_products_text"
android:layout_below="@id/btn_main_contactus"
android:layout_marginTop="10dp"
android:layout_alignParentRight="true"
android:background="@color/background_btn"
android:textColor="@color/text_color_btn" />
<Button
android:id="@+id/btn_main_news"
android:layout_width="120dp"
android:layout_height="120dp"
android:text="@string/btn_news_text"
android:layout_below="@id/btn_main_products"
android:layout_marginTop="10dp"
android:layout_alignParentRight="true"
android:background="@color/background_btn"
android:textColor="@color/text_color_btn" />
</RelativeLayout>
我假设您希望在垂直行中有4个按钮(水平居中)。如果我理解正确,您应该使用LinearLayout,通过它可以指定不同组件的重量。把它当作优先事项。如果按钮都有相同的重量,它们都将缩放以适应屏幕 将RelativeLayout更改为LinearLayout并添加属性:
android:orientation="vertical"
所有按钮应具有相同的高度,并且
android:layout_centerHorizontal="true"
您可以删除
android:layout_below="@id/btn_main_aboutus
然后根据需要添加您的边距和偏好。介意解释下一票吗?所以也许我可以编辑和改进这个问题???你的基本布局是什么?我认为查看布局xml文件会有所帮助。dp是衡量事物大小的正确方法(除了应该使用sp的字体),你能发布你的xml代码吗?@Rickard更新了这个问题。