Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/198.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
简单的Android布局调整_Android_Xml_Android Layout_Android Linearlayout_Android Button - Fatal编程技术网

简单的Android布局调整

简单的Android布局调整,android,xml,android-layout,android-linearlayout,android-button,Android,Xml,Android Layout,Android Linearlayout,Android Button,我正在尝试调整“旋转”按钮的大小以按比例展开。现在,它们是固定长度的,但我不确定是否有其他方法可以调整按钮的大小(设置权重似乎没有帮助)。我希望按钮基本上可以垂直和水平地填充屏幕的长度。如果你需要更多信息,请告诉我 <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_

我正在尝试调整“旋转”按钮的大小以按比例展开。现在,它们是固定长度的,但我不确定是否有其他方法可以调整按钮的大小(设置权重似乎没有帮助)。我希望按钮基本上可以垂直和水平地填充屏幕的长度。如果你需要更多信息,请告诉我

 <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:layout_gravity="center_vertical" >

            <Button
                android:id="@+id/mainCommentBtn"
                android:layout_width="119dp"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:clickable="true"
                android:focusable="false"
                android:focusableInTouchMode="false"
                android:layout_weight="1"
                android:text="@string/commentBtn" />

            <Button
                android:id="@+id/mainProfileBtn"
                android:layout_width="119dp"
                android:layout_height="wrap_content"
                android:clickable="true"
                android:focusable="false"
                android:focusableInTouchMode="false"
                android:layout_weight="1"
                android:layout_centerInParent="true"
                android:text="@string/profileBtn" />

            <Button
                android:id="@+id/mainDetailBtn"
                android:layout_width="119dp"
                android:clickable="true"
                android:focusable="false"
                android:focusableInTouchMode="false"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:text="@string/shareBtn" />
        </LinearLayout>

用这个替换您的资源。复制已编辑的更改

注意宽度是0dp,因为它们使用的是重量。 使用重量: 1.为了使用权重,您需要在父级中设置权重和。 2.根据您使用重量的方式,确保宽度或高度设置为0。 (例如,由于我们使用水平方向,我们希望使用“0dp”宽度。这允许权重控制对象的宽度。 3.最后确保所有物体的重量加起来等于重量总和

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginTop="5dp"
android:orientation="horizontal"
android:weightSum="3" >

<Button
    android:id="@+id/mainCommentBtn"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_weight="1"
    android:clickable="true"
    android:focusable="false"
    android:focusableInTouchMode="false"
    android:text="@string/commentBtn" />

<Button
    android:id="@+id/mainProfileBtn"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:layout_weight="1"
    android:clickable="true"
    android:focusable="false"
    android:focusableInTouchMode="false"
    android:text="@string/profileBtn" />

<Button
    android:id="@+id/mainDetailBtn"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_weight="1"
    android:clickable="true"
    android:focusable="false"
    android:focusableInTouchMode="false"
    android:text="@string/shareBtn" />

</LinearLayout>

您需要为
线性布局指定方向

我想你应该使用android:orientation=“horizontal”

然后,为了使
android:weight
工作,您需要为每个按钮使用
android:layout\u width=“0px”
将每个按钮的宽度指定为
0px


    <Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:text="Button" />

这些xml属性调整按钮的大小,以垂直和水平填充屏幕。

您可以借助布局权重创建布局,以便在横向模式下自动填充屏幕,如下所示:

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="3" >
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button 1"
            android:layout_weight="1" />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button 2"
            android:layout_weight="1" />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button 3"
            android:layout_weight="1" />
    </LinearLayout>


如果你能给你的答案添加一些解释,那就太好了。啊,明白了。对不起,我的坏。np我试着给他多画了一点。体重可能会让人困惑,一开始就理解不了。不幸的是,这实际上没什么用:(确保你把它放进一个资源文件中,我会做必要的更改