【发布时间】:2014-01-19 21:35:01
【问题描述】:
我正在开发一个 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>
那么如何让按钮文本大小在不同的屏幕尺寸上自动调整,而不必为不同的屏幕尺寸制作不同的布局?
请帮我写代码,因为我几乎是个初学者!
提前致谢!
【问题讨论】:
-
@StarsSky 我想避免制作不同的文件夹,并正在寻找一种解决方案来制作支持所有屏幕尺寸的单一布局。如果您有解决方案,请帮助我。谢谢!
-
引入了不同的布局文件夹以满足您的要求
-
是的,我知道,但这就是我想要避免的。我只想要一种可以自动适应所有屏幕尺寸的布局。我通过使用“layout_weight”完成了一半,但我被按钮的文本大小困住了。如果您有解决方案,请帮助我。谢谢!
-
尝试在你的按钮中使用 textsite in sp。