Krz*_*ski 1 xml android android-layout
我想在一个TableRow中使用TextView和EditText,我希望EditText的宽度比TextView大两倍,所以我把它放在TextView区域:
android:layout_weight="1"
Run Code Online (Sandbox Code Playgroud)
在EditText区域:
android:layout_weight="2"
Run Code Online (Sandbox Code Playgroud)
但它看起来不正确:
我的整个.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableRow
android:id="@+id/imageButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="8dp" >
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:maxHeight="150dp"
android:maxWidth="150dp"
android:scaleType="centerInside"
android:src="@drawable/add_user" />
</TableRow>
<TableRow
android:id="@+id/loginRow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp" >
<TextView
android:id="@+id/loginTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/login_text_view" />
<EditText
android:id="@+id/loginEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:inputType="text" >
<requestFocus />
</EditText>
</TableRow>
<TableRow
android:id="@+id/passwordRow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp" >
<TextView
android:id="@+id/passwordTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/password_text_view" />
<EditText
android:id="@+id/passwordEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:inputType="textPassword" />
</TableRow>
<TableRow
android:id="@+id/nameRow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp" >
<TextView
android:id="@+id/nameTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/name_text_view" />
<EditText
android:id="@+id/nameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:inputType="text" />
</TableRow>
<TableRow
android:id="@+id/countryRow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp" >
<TextView
android:id="@+id/countryTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/country_text_view" />
<EditText
android:id="@+id/countryEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:inputType="text" />
</TableRow>
<TableRow
android:id="@+id/phoneRow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp" >
<TextView
android:id="@+id/phoneTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/phone_text_view" />
<EditText
android:id="@+id/phoneEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:inputType="text|phone" />
</TableRow>
<TableRow
android:id="@+id/buttonRow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp" >
<Button
android:id="@+id/addUserButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/add_user_button" />
</TableRow>
</TableLayout>
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
对于每个TextView和EditText,更改android:layout_width="match_parent"为android:layout_width="0dp"
这将解决它.
| 归档时间: |
|
| 查看次数: |
1447 次 |
| 最近记录: |