Câu hỏi này kể cho tôi từ các bước đầu tiên của tôi với Android. Tôi không thể tạo cả hai cột trong TableLayout 2 cột chính xác 50% mỗi cột.TableLayout 2 cột với 50% chính xác cho mỗi cột
Dưới đây là một ví dụ:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="fill_parent" >
<TableLayout
android:id="@+id/tablelayout"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:paddingRight="2dip" >
<TableRow>
<TextView
style="@style/TextViewStandard"
android_layout_span="2"
android:layout_weight="1"
android:text="Bla" />
</TableRow>
<TableRow>
<TextView
style="@style/TextViewStandard"
android:layout_weight="1"
android:text="Name:" />
<EditText
style="@style/EditTextStandard"
android:id="@+id/et_name"
android:layout_weight="1" />
</TableRow>
<TableRow>
<TextView
style="@style/TextViewStandard"
android:layout_weight="1"
android:text="URL:" />
<EditText
style="@style/EditTextStandard"
android:id="@+id/et_url"
android:layout_weight="1" />
</TableRow>
<TableRow>
<Button
style="@style/ButtonStandard"
android:layout_column="0"
android:layout_marginTop="6dip"
android:onClick="onClickOk"
android:text="@android:string/ok" />
</TableRow>
</TableLayout>
</ScrollView>
Và đây là định nghĩa kiểu tương ứng:
<resources>
<style name="ButtonStandard" parent="@android:style/Widget.Button">
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">fill_parent</item>
</style>
<style name="EditTextStandard" parent="@android:style/Widget.EditText">
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginLeft">2dip</item>
<item name="android:layout_marginRight">2dip</item>
<item name="android:layout_marginTop">2dip</item>
<item name="android:layout_width">fill_parent</item>
</style>
<style name="TextViewStandard" parent="@android:style/Widget.TextView">
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginLeft">2dip</item>
<item name="android:layout_marginRight">2dip</item>
<item name="android:layout_marginTop">2dip</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:textColor">@android:color/white</item>
</style>
</resources>
này trở nên thực sự sai lầm với một CheckBox có liên quan.
Có gì sai với định nghĩa của tôi?
Rất cám ơn trước. HJW
Quan trọng hơn, nếu bạn làm điều này, hãy đổ 'TableLayout' và chuyển sang' LinearLayout'. 'TableLayout' được thiết kế cho các trường hợp bạn cần Android để tính toán độ rộng cột dựa trên nội dung ô. Nếu bạn cố ý bỏ qua điều đó, bạn cũng có thể sử dụng 'LinearLayouts' lồng nhau thay thế. – CommonsWare
@ChristianB: Cảm ơn bạn đã giải thích. Tôi luôn nghĩ rằng phải có một cái gì đó "sai" với TableLayout. Điều thú vị là nhiều TableLayouts không hoạt động hoàn hảo với trình giả lập 2.3. @dbm: Với layout_width đặt thành 0dp tất cả các chế độ xem con (TextView/EditText) biến mất. Dù sao cũng cảm ơn bạn. Tôi sẽ kiểm tra giải pháp của CommonsWares và thả hoàn toàn TableLayouts. Không biết những gì họ là tốt cho nếu bạn cần phải biết những gì có thể được in trong họ và có thể mess chúng lên ... –
@CommonsWare: Không thể tin tại sao tôi đã TableLayouts? Thay đổi chúng thành LinearLayout hoạt động hoàn hảo. Cảm ơn nhiều. –