gpt4 book ai didi

android - 使用非 9 补丁按钮的可缩放应用程序大小

转载 作者:行者123 更新时间:2023-11-30 03:31:07 25 4
gpt4 key购买 nike

我目前正在学习 Android 开发,在我完全投入到一个大型项目之前,我决定我需要学习如何让应用程序可以从尽可能多的设备访问。

所以我有一个使用 RelativeLayout 的测试应用程序。顶层 Activity 有 6 个大菜单按钮。这些按钮是方形图形图像(不是 9 补丁按钮,因为它们 - 据我所知 - 在图形上太原始了)。在我用于测试的设备上,这些按钮以完美的 2x3 排列方式出现,如下所示:

Buttons laid out perfectly in 3x2 arrangement

但是,当我尝试在更大的设备上运行此应用程序时,按钮将如下所示:

enter image description here

有没有办法根据屏幕大小缩放非 9 补丁按钮,以便它们始终显示为第一个图像?这是推荐的吗?如果没有,是否有针对不同屏幕尺寸进行此类布局的替代方法?

我理想中的布局可以跨不同的设备进行扩展,如下所示:

enter image description here

最佳答案

我正在使用类似的菜单。这是它的第一行。此菜单中的按钮也有标签。

        <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 个按钮之间留出空格,而不是在屏幕边框和按钮之间留出空格。

关于android - 使用非 9 补丁按钮的可缩放应用程序大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17469020/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com