Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/233.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 XML布局-百分比+;包装内容_Android_Xml_Layout - Fatal编程技术网

Android XML布局-百分比+;包装内容

Android XML布局-百分比+;包装内容,android,xml,layout,Android,Xml,Layout,我想做一些布局的部分,比如: [_____EditText1_____] / [_____EditText2_____] 我不想在dp/px等中设置宽度。 我想将内容包装为“斜杠”符号“/”的宽度,并将EditText1和EditText2的剩余宽度除以(50%到50%)。 只需对EditText1和EditText2进行简单设置即可: android:layout_width="0dp" android:layout_weight=".5" 但是如何在两个编辑文本之间设置文本视图“/”和宽

我想做一些布局的部分,比如:

[_____EditText1_____] / [_____EditText2_____]
我不想在dp/px等中设置宽度。 我想将内容包装为“斜杠”符号“/”的宽度,并将EditText1和EditText2的剩余宽度除以(50%到50%)。 只需对EditText1和EditText2进行简单设置即可:

android:layout_width="0dp"
android:layout_weight=".5"
但是如何在两个编辑文本之间设置文本视图“/”和宽度换行内容?

试试以下方法:

<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <EditText
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="0.48" />

    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="/"
        android:layout_weight="0.04" />

    <EditText
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="0.48" />

</LinearLayout>

您可以试试这个

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <EditText 
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"/>

    <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="/"/>

    <EditText 
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"/>

</LinearLayout>

TextView
将占据其空间,剩余部分将在
EditView
s之间平均分配

希望这有帮助。


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

   <EditText
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_weight=".5"
   />

  <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="/" />
 <EditText
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_weight=".5"
 />
</LinearLayout>

关键是增加中间元素的
布局权重
值;)

<LinearLayout
        android:layout_height="wrap_content"
        android:layout_width="fill_parent">
        <TextView
            android:layout_weight="1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="0"
            android:gravity="center_vertical|center_horizontal" />
        <TextView
            android:layout_weight="1.5"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="/"
            android:gravity="center_vertical|center_horizontal" />
        <TextView
            android:layout_weight="1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="0"
            android:gravity="center_vertical|center_horizontal" />
   </LinearLayout>