我遇到了问题。在我的应用程序中,我有一些(3-4)按钮需要自动缩放到全屏尺寸。 (不是只有一个按钮,但所有的一起)。目前,我正在为我的应用使用LinearLayout。它可以做到这一点吗? 对不起,我的英语不好。Android:将几个按钮缩放到屏幕大小
问候尼尔斯
游戏“Dont't挖掘白”的那个屏幕类似于像我想它:
我遇到了问题。在我的应用程序中,我有一些(3-4)按钮需要自动缩放到全屏尺寸。 (不是只有一个按钮,但所有的一起)。目前,我正在为我的应用使用LinearLayout。它可以做到这一点吗? 对不起,我的英语不好。Android:将几个按钮缩放到屏幕大小
问候尼尔斯
游戏“Dont't挖掘白”的那个屏幕类似于像我想它:
可以使用重量概念吧。你的按钮在所有屏幕上看起来都一样。
首先在两个水平部分划分屏幕,每个宽度重量为50 50,高度与父对齐。然后在高度添加3个按钮的每个零件与重量为33.33如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_weight="50"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="33.33"
android:text="Button" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="33.33"
android:text="Button" />
<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="33.33"
android:text="Button" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="50"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/button4"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="33.33"
android:text="Button" />
<Button
android:id="@+id/button5"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="33.33"
android:text="Button" />
<Button
android:id="@+id/button6"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="33.33"
android:text="Button" />
</LinearLayout>
</LinearLayout>
您可以用更干净的值替换您的权重,如“1”,因为它是用于计算分布的这些值的实际总和剩余的 – jcxavier
jcxavier我们可以使用1或100两者来分配权重 –
丑陋溶液将使用3个加权LinearLayouts(具有相同的重量)垂直,而使用加权水平的LinearLayout来达到同样的水平影响。
或者你可以使用一个GridView以更优雅的方式来达到类似的效果:http://developer.android.com/guide/topics/ui/layout/gridview.html
巴顿设置宽度match_parent。然后它将按比例缩放以适合父母。
是的。您可以使用LinearLayout来做到这一点。你必须设置机器人:layout_weight =“”到buttons..it取决于水平和垂直方向给出的权重的按钮的数目..
请告诉我你有多少个按钮水平和垂直..然后我会在这里发布LinearLayout的代码.. –
好的..我有相同的代码作为上述答案,你已经接受..但我正在等待我们的回应给出你想要的确切答案......任何方式......我想我的答案值得投票:) –
使用该XML代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="2" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2">
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="Button"
android:layout_weight="1" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="Button"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2" >
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="Button"
android:layout_weight="1" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="Button"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
设定宽度“FILL_PARENT”为每个按钮 –
我认为3水平模式相对布局与父母的左侧和父母权利可以帮助你。只是其中一种方法闪现我的想法 – Umitk
3垂直LinearLayout中具有相同权重的水平面向linearLayout – user3455363