Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/441.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
Javascript 具有两个按钮的布局设计问题_Javascript_Android_Android Layout_Layout - Fatal编程技术网

Javascript 具有两个按钮的布局设计问题

Javascript 具有两个按钮的布局设计问题,javascript,android,android-layout,layout,Javascript,Android,Android Layout,Layout,我想设计满足以下要求的布局: 1。最初有两个按钮。一个挨着另一个 2.如果需要增加按钮1的文本,请向右移动按钮2 3.问题是,当你增加更多文本时,按钮2会收缩,这是我不希望看到的,我希望按钮2不会收缩,而按钮1应该收缩。 设计应该像屏幕截图上显示的那样。 如何以呈现的方式设计布局?请尝试以下方法: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://sc

我想设计满足以下要求的布局:

1。最初有两个按钮。一个挨着另一个

2.如果需要增加按钮1的文本,请向右移动按钮2

3.问题是,当你增加更多文本时,按钮2会收缩,这是我不希望看到的,我希望按钮2不会收缩,而按钮1应该收缩。

设计应该像屏幕截图上显示的那样。 如何以呈现的方式设计布局?

请尝试以下方法:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent">

<Button
    android:id="@+id/button1"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="0.1"
    android:text="Button" />

<Button
    android:id="@+id/button2"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="0.1"
    android:text="Button" />


实现这一目标的选项很少

  • 使用LinearLayout添加
    weightSum=“3”
    并向孩子们提供
    layout\u weight=“integer”
    。 在这种情况下,必须采用比率格式ex:2:1,同时确保
    layout\u width=“0dp”

  • 使用
    相对布局
    ,将按钮2放置在
    按钮1的
    右侧,并将
    最小宽度=“100dp”
    (调整大小)设为按钮2


  • 在布局中使用以下选项

     <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:weightSum="2"
        >
    
        <Button
            android:id="@+id/button1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Button" />
    
        <Button
            android:id="@+id/button2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Button" />
    
    </LinearLayout>
    
    
    
    尝试以下代码:


    试试这个,它正在工作:

     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/LinearLayout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">
    
        <Button
            android:id="@+id/button1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.5"
            android:text="Button" />
    
        <Button
            android:id="@+id/button2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.5"
            android:text="Button" />
    
        </LinearLayout>   
    
    
    

    它也适用于所有设备。

    您需要将按钮包装在另一个线性布局中才能工作。我就是这样做的:

    <?xml version="1.0" encoding="utf-8"?>
    
    
    

    
    

    这是我能找到的最接近的了。如果您能找出如何使其在总体布局中左对齐而不是右对齐,则它将符合您列出的要求:

    <RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="0" >
    
    <Button
        android:id="@+id/test_button_0"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:text="Normal" >
    </Button>
    
    <Button
        android:id="@+id/test_button_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@+id/test_button_0"
        android:lines="1"
        android:text="This could be very, very, very, long..." >
    </Button>
    </RelativeLayout>
    
    
    

    通过使用相对布局而不是线性布局,此方法可以将右边的按钮放在XML代码的第一位。首先出现的子项是布局管理器不会挤压的子项,似乎。

    我不能使用权重,因为按钮内的文本会导致按钮的扩展。通过将android:singleline设置为true以查看我的Ans,您可以避免这种情况。此设计会导致1屏幕截图失败。请检查是否将小文本提供给按钮否不会导致1屏幕截图失败。仔细检查。为按钮指定宽度0 dp按钮的宽度不得为父按钮的一半。宽度必须取决于按钮的文本。清楚地检查屏幕快照1请检查添加到问题中的注释。感谢you@user3607798使用我的
    2
    选项,这将满足上述所有要求。对不起..按钮2仍在缩小请检查添加到问题中的注释它对我有效。满足您的所有要求。尝试在按钮1上使用小文本…这将无法满足屏幕快照1担心的老板!但它也适用于我的小文本。我认为你做错了什么。一旦通过减少按钮1的文本来检查答案,我知道它会缩小,因为它设置为包装内容,只需更改它以匹配家长您也需要自己做事情我们只是以自己的方式来帮助,我们也希望得到帮助我会编辑我的ans
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1" >
    
        <Button
            android:id="@+id/button1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:singleLine="true"
            android:text="Button is really really long haha" />
    </LinearLayout>
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1" >
    
        <Button
            android:id="@+id/button2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Button" />
    </LinearLayout>
    
    <RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="0" >
    
    <Button
        android:id="@+id/test_button_0"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:text="Normal" >
    </Button>
    
    <Button
        android:id="@+id/test_button_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@+id/test_button_0"
        android:lines="1"
        android:text="This could be very, very, very, long..." >
    </Button>
    </RelativeLayout>