在tablerow中设置edittext宽度

时间:2016-05-09 17:45:55

标签: android android-edittext width

我有一个带有tablerows的tableview,输出是这个(Background = shape)

这两个edittext具有相同的大小 - 但我希望第一个edittext填充来自'的其余部分:'在第二个逗留时间更短,可能是7个字母。

任何帮助?

Picture

      <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>

2 个答案:

答案 0 :(得分:0)

将TextView和EditText包装在RelativeLayout(与父级匹配,在本例中为TableRow)中,并将它们相对于彼此和父视图放置。 F.E.你的EditText如果你希望它从match ::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"

答案 1 :(得分:0)

尝试以这种方式实现Table行:

<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>
相关问题