这是我的XML for LAND格式的一部分:
<TableLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:stretchColumns="*">
<TableRow>
<Button
android:id="@+id/countbutton"
android:text="@string/plus1"/>
<Button
android:id="@+id/resetbutton"
android:text="@string/reset"
/>
</TableRow>
</TableLayout>
Run Code Online (Sandbox Code Playgroud)
现在我得到的东西 - 一行的宽度和按钮的宽度取决于按钮内的TEXT.如果这两个文本都是等长的,那就说:TEXT它没关系 - 表格的一半位于屏幕中间.但如果它们有不同的尺寸 - 让我们说"A"和"这就是长按钮",桌子的中心不再在屏幕中间,所以按钮宽度不一样......
我正在开发一个使用的屏幕TableLayout.在这里,我可以轻松创建两列.但是如何创建三列呢?
为什么我的表没有相同的列宽?这是完整的布局:首先是表格,然后是表格外的LinearLayout中的两个按钮,它们被平分.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="4dp" >
<TableRow
android:layout_marginTop="2dp"
android:gravity="center_vertical" >
<TextView
style="@style/Label.Plain"
android:layout_width="match_parent"
android:text="@string/Caption" />
<EditText
android:background="#00ff00"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="@dimen/button_height"
android:inputType="numberDecimal"
android:selectAllOnFocus="true"
android:textSize="@dimen/spinner_text" />
</TableRow>
</TableLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:layout_marginBottom="3dp"
android:gravity="center_vertical"
android:orientation="horizontal" >
<Button
android:id="@+id/btnOk"
style="@style/Button.Plain.Fill"
android:layout_weight="1"
android:text="@string/ALS_OK" />
<Button
android:id="@+id/btnClose"
style="@style/Button.Plain.Fill"
android:layout_weight="1"
android:text="@string/CANCEL" />
</LinearLayout>
</LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
这是它的外观(一列为可见性绘制):

我可以在这里使用线性布局,只是想了解背后的逻辑TableLayout.