因为我试图在android页面中使用表格布局的拉伸列属性来使用表格布局 这是代码
<TableLayout
style="@style/TableLayoutStyle"
android:stretchColumns="1"
><------- Column property for column 2nd only
<!-- Lable Area -->
<TableRow
android:id="@+id/tblRwSpnLbl"
style="@style/TableRowStyle" >
<TextView
android:id="@+id/lblCust"
style="@style/LabelStyle"
android:fontFamily="verdana,arial,helvetica"
android:text="@string/lblCust" />
<Spinner
android:id="@+id/spnCust"
style="@style/SpinnerStyle"
android:fontFamily="verdana,arial,helvetica"
android:hint="@string/SelectCust" />
</TableRow>
<!-- Spinner Area -->
<TableRow
android:id="@+id/tblRwSpn"
style="@style/TableRowStyle" >
<TextView
android:id="@+id/lblPros"
style="@style/LabelStyle"
android:fontFamily="verdana,arial,helvetica"
android:text="@string/lblPros" />
<Spinner
android:id="@+id/spnPospect"
style="@style/SpinnerStyle"
android:fontFamily="verdana,arial,helvetica"
android:hint="@string/SelectProspect" />
</TableRow>
<!-- Text Area -->
<TableRow
android:id="@+id/tblRwEditTxt"
style="@style/TableRowStyle" >
<TextView
android:id="@+id/lblCommo"
style="@style/LabelStyle"
android:fontFamily="verdana,arial,helvetica"
android:text="@string/lblCommo" />
<Spinner
android:id="@+id/spnComodity"
style="@style/SpinnerStyle"
android:fontFamily="verdana,arial,helvetica" />
</TableRow>
<!-- Button Submit Section -->
<TableRow
android:id="@+id/tblRwOESubmit"
style="@style/TableRowStyle"
android:background="@drawable/border"
android:gravity="center" >
<!-- Lable Area -->
<TextView
android:id="@+id/lblCust1"
android:fontFamily="verdana,arial,helvetica"
android:text="@string/strNull" />
<TableLayout
style="@style/TableLayoutStyle"
android:background="@drawable/border" >
<!-- Lable Area -->
<TableRow
android:id="@+id/tblRwSpnLbl1"
style="@style/TableRowStyle"
android:background="@drawable/border"
android:gravity="left" >
<Button
android:id="@+id/btnEdit"
style="@style/ButtonStyle"
android:layout_margin="10dp"
android:fontFamily="verdana,arial,helvetica"
android:text="@string/edit" />
<Button
android:id="@+id/btnCancel"
style="@style/ButtonStyle"
android:fontFamily="verdana,arial,helvetica"
android:text="@string/cancel" />
</TableRow>
</TableLayout>
</TableRow>
<TableRow
android:id="@+id/tblRwOESubmit1"
style="@style/TableRowStyle"
android:background="@drawable/border"
android:gravity="center" >
<Button
android:id="@+id/btnEdit1"
style="@style/ButtonStyle"
android:layout_margin="10dp"
android:fontFamily="verdana,arial,helvetica"
android:text="@string/edit" />
<Button
android:id="@+id/btnCancel1"
style="@style/ButtonStyle"
android:fontFamily="verdana,arial,helvetica"
android:text="@string/cancel" />
</TableRow>
</TableLayout>
最后一行是按钮Edit&amp;取消想要在特定行的中心显示它们但是它在图像(2)中显示我在拉伸的行中所以想要停止伸展该特定行的按钮 如下图所示(3)如何实现这一点,因为我努力完成它们但仍然不在中心(1)
<style name="ButtonStyle" parent="@android:style/Widget.Button">
<item name="android:textColor">#FFFFFF</item>
<item name="android:textSize">18sp</item>
<item name="android:textStyle">bold</item>
<item name="android:layout_width">85dp</item>
<item name="android:layout_gravity">center_vertical</item>
<item name="android:paddingLeft">10dp</item>
<item name="android:layout_height">35dp</item>
<item name="android:layout_marginLeft">10dp</item>
<item name="android:paddingRight">10dp</item>
<item name="android:layout_marginBottom">10dp</item>
<item name="android:layout_marginTop">10dp</item>
<item name="android:background">@drawable/press_btn_effct</item>
</style>
答案 0 :(得分:1)
这里我得到了中心按钮的解决方案
<TableRow
android:id="@+id/tblRwOESubmit"
style="@style/TableRowStyle"
android:background="#bcbcbc"
android:gravity="center" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_marginLeft="5dp"
android:layout_span="2"<-----used it with linear layout
android:gravity="center" >
<Button
android:id="@+id/btnSubmit"
style="@style/ButtonStyle"
android:layout_margin="10dp"
android:fontFamily="verdana,arial,helvetica"
android:text="@string/submit" />
<Button
android:id="@+id/btnCancel"
style="@style/ButtonStyle"
android:fontFamily="verdana,arial,helvetica"
android:text="@string/cancel" />
</LinearLayout>
</TableRow>
答案 1 :(得分:0)
在布局中使用android:layout_column
属性,如下所示。
的修改
随意根据您的要求进行更改。
<TableRow
android:id="@+id/tblRwOESubmit1"
style="@style/TableRowStyle"
android:background="@drawable/border"
android:gravity="center" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_column="1" // For placing button in 2nd column
android:orientation="horizontal" >
<Button
android:id="@+id/btnEdit1"
style="@style/ButtonStyle"
android:layout_margin="10dp"
android:fontFamily="verdana,arial,helvetica"
android:text="@string/edit" />
<Button
android:id="@+id/btnCancel1"
style="@style/ButtonStyle"
android:fontFamily="verdana,arial,helvetica"
android:text="@string/cancel" />
</<LinearLayout>
</TableRow>