【问题标题】:set edittext width in tablerow在tablerow中设置edittext宽度
【发布时间】:2016-09-04 11:12:42
【问题描述】:

我有一个带有表格行的表格视图,输出是这样的(背景 = 形状)

两个编辑文本具有相同的大小 - 但我希望第一个编辑文本从 ':' 开始填充该行的其余部分,第二个可能保持较短的 7 个字母。

有什么帮助吗?

      <TableLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/BackGC"
           >
<TableRow
    android:orientation="horizontal"
    android:layout_margin="5dp"
    android:padding="3dp"
    android:background="@drawable/editdef"
    android:layout_width="match_parent"
  >

    <TextView
        android:id="@+id/tView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/tvname"
        android:textSize="21sp"
        android:textStyle="bold"
        android:paddingLeft="5dp"

        />

    <EditText
            android:id="@+id/edName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/btnpress"
            android:hint="@string/lname"
            android:singleLine="true"
            android:textColor="#999999"
            android:textSize="21sp"
            android:textStyle="bold"


            />

</TableRow>
            <TableRow
                android:orientation="horizontal"
                android:layout_margin="5dp"
                android:padding="3dp"
                android:background="@drawable/editdef"   >
                <TextView
                    android:id="@+id/textView2"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/tvlang"
                    android:textSize="21sp"
                    android:textStyle="bold"
                    android:paddingLeft="5dp"
                    />


                <EditText
            android:id="@+id/edLang"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/edtbg"
            android:hint="@string/lname"

            android:singleLine="true"
            android:textColor="#999999"
            android:textSize="21sp"
            android:textStyle="bold"
            />
            </TableRow>



... </tablelayout>

【问题讨论】:

    标签: android android-edittext width


    【解决方案1】:

    尝试以这种方式实现表格行:

    <TableRow
        android:orientation="horizontal"
        android:layout_width="match_parent"
       >
       <RelativeLayout
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:layout_margin="5dp"
           android:padding="3dp"
           android:background="@drawable/editdef"
          >
          <TextView
            android:id="@+id/tView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/tvname"
            android:textSize="21sp"
            android:textStyle="bold"
            android:paddingLeft="5dp"
            android:alignParentLeft="true"
            />
          <EditText
            android:id="@+id/edName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/btnpress"
            android:hint="@string/lname"
            android:singleLine="true"
            android:textColor="#999999"
            android:textSize="21sp"
            android:textStyle="bold"
            android:layout_toRightOf="@+id/tView1"
            />
       </RelativeLayout>
    
    </TableRow>
    

    【讨论】:

      【解决方案2】:

      将您的 TextView 和 EditText 包装在 RelativeLayout(匹配父级,在本例中为 TableRow)中,并将它们相对于彼此和父视图定位。 F.e.如果您希望 EditText 从 : 开始匹配_parent,则可以是 toRightOf(或 toEndOf)您的文本视图,并且还可以将 alighParentEnd(或 Right)设置为 true。或者(或另外)您可以设置边距和填充以达到您想要的美学效果。

      I tried a Little bit :) - now the edittext is near the textview but I did not achive howto fit the edittext to the parentend     <EditText
              android:id="@+id/edName"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:background="@color/btnpress"
              android:hint="@string/lname"
              android:singleLine="true"
              android:textColor="#999999"
              android:textSize="21sp"
              android:textStyle="bold"
              android:layout_toEndOf="@+id/tView1"
          android:layout_toRightOf="@+id/tView1"
          android:layout_alignParentEnd="true"
          android:layout_alignParentRight="true"
      

      【讨论】:

      • 我看到你编辑了我的答案。尝试将宽度设置为 match_parent。然后它应该对齐两端(文本视图和父布局的结尾)。确保父级是RelativeLayout。
      • 这就是为什么您需要将编辑文本的宽度设置为 match_parent
      猜你喜欢
      • 2011-09-19
      • 2021-10-30
      • 1970-01-01
      • 1970-01-01
      • 2020-01-28
      • 1970-01-01
      • 2011-09-22
      • 2014-02-16
      • 1970-01-01
      相关资源
      最近更新 更多