我目前正在学习android开发,在我遇到大型项目之前,我决定需要学习如何使用尽可能多的设备访问应用程序。
所以我有一个使用RelativeLayout
的测试应用程序。顶级活动上有6个大菜单按钮。这些按钮是方形图形图像(不是9个补丁按钮,据我所知 - 图形太原始)。在我用于测试的设备上,这些按钮以完美的2x3排列显示,如下所示:
但是,当我尝试在较大的设备上运行此应用程序时,按钮将如下所示:
有没有办法根据屏幕尺寸缩放非9个补丁按钮,这样它们总是会像第一个图像一样显示?这是推荐的吗?如果没有,是否有另一种方法可以针对不同的屏幕尺寸进行这样的布局?
我理想的布局可以在不同的设备上进行扩展,如下所示:
答案 0 :(得分:1)
我正在使用类似的菜单。这是第一排。此菜单中的按钮也有标签。
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:gravity="center" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dip" >
<Button
android:id="@+id/screen_home_btn_profile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/selector_ic_my_profile" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:paddingBottom="5dip" >
<TextView
style="@style/label_text_style_home_screen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/screen_home_label_my" />
<TextView
style="@style/label_text_style_home_screen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/screen_home_label_profile"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dip" >
<Button
android:id="@+id/screen_home_btn_application"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/selector_ic_my_application" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:paddingBottom="5dip" >
<TextView
style="@style/label_text_style_home_screen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/screen_home_label_my" />
<TextView
style="@style/label_text_style_home_screen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/screen_home_label_application"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
看来你正在为按钮提供外边距。将它们对准中心,并在2个按钮之间留出空间,而不是屏幕边框和的按钮。