gpt4 book ai didi

Android - 所有屏幕尺寸的按钮文字大小

转载 作者:太空狗 更新时间:2023-10-29 16:39:04 31 4
gpt4 key购买 nike

我正在开发一个 Android 应用程序,我在屏幕顶部有 3 个按钮,我已经使用 layout_weight 属性定义了它们。这些按钮会适应所有屏幕尺寸,包括平板电脑,但其文字不会。

这是它在 nexus 5 上的样子:

这是它在 nexus 10 上的样子:

看出区别了吗?
在 nexus 5 上,它非常清晰,但在 nexus 10 上你几乎看不到任何东西!

这是我的XML:

<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:background="#000000"
android:orientation="horizontal"
android:weightSum="3" >

<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="Button 1"
android:layout_weight="1"
android:id="@+id/button" />

<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="Button 2"
android:layout_weight="1"
android:id="@+id/button2" />

<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="Button 3"
android:layout_weight="1"
android:id="@+id/button3" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center_vertical"
android:background="#000000"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="3" >

</LinearLayout>


<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:background="#000000"
android:orientation="horizontal"
android:weightSum="3" >

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:background="#000000"
android:orientation="horizontal"
android:weightSum="3" >

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:background="#000000"
android:orientation="horizontal"
android:weightSum="3" >

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:background="#000000"
android:orientation="horizontal"
android:weightSum="3" >

</LinearLayout>

那么如何让按钮文字大小在不同的屏幕尺寸上自动调整,而不需要为不同的屏幕尺寸做不同的布局呢?

请帮助我完成代码,因为我几乎是一个初学者!

提前致谢!

最佳答案

您目前正在尝试扩展整个应用程序,而不是构建合适的平板电脑用户界面。您将按钮的宽度设置为屏幕的 1/3,这是按预期工作的。您没有更改按钮的文本大小,因此 Android 会选择默认的文本大小。默认的 textSizes 是一个特定的大小,独立于 View 的尺寸。您不能(也不想)将完整的 UI 扩展为在 4 英寸手机和 10 英寸平板电脑上相同。

您不能仅在一个布局中为手机和平板电脑构建(适当的)用户界面,因为您应该在平板电脑上显示比在手机上更多的信息。尽管您可以重复使用大部分布局。您可能想阅读 Supporting Different Screen Sizes Android 开发者网站上的培训。

关于Android - 所有屏幕尺寸的按钮文字大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21217305/

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