Android在表格布局中对齐按钮和文本
我正在尝试在android中创建一个带有文本视图和按钮的表视图。下面是我的示例代码(正在工作)。由于我是android新手,请帮助我如何安排文本视图和按钮,如图所示。现在我得到了按钮和文本视图。但这很奇怪 我的代码Android在表格布局中对齐按钮和文本,android,uitableview,android-layout,android-ui,Android,Uitableview,Android Layout,Android Ui,我正在尝试在android中创建一个带有文本视图和按钮的表视图。下面是我的示例代码(正在工作)。由于我是android新手,请帮助我如何安排文本视图和按钮,如图所示。现在我得到了按钮和文本视图。但这很奇怪 我的代码 TableLayout table = (TableLayout)findViewById(R.id.tableLayout_1); for (int i = 0; i<30; i++) { TableRow row = new TableRow(th
TableLayout table = (TableLayout)findViewById(R.id.tableLayout_1);
for (int i = 0; i<30; i++)
{
TableRow row = new TableRow(this);
row.setBackgroundColor(Color.DKGRAY);
TextView tv = new TextView(this);
Button btn=new Button(this);
tv.setTextAppearance(getApplicationContext(), R.style.maxWid);
tv.setText("Sample Text Here");
row.addView(tv);
btn.setText("Approves");
row.addView(btn);
table.addView(row);
}
TableLayout table=(TableLayout)findViewById(R.id.TableLayout_1);
对于(int i=0;i您可以在这里使用RelativeLayout
创建一个布局xml,然后将其添加到您的表格行
谢谢您的评论..很抱歉,我不理解您的答复..我的错!!您能给我一个示例代码吗?创建一个布局xml文件,将RelativeLayout作为根节点..然后ce TextView中的宽度作为填充内容,高度作为环绕内容。然后添加一个按钮,并将重心作为中心垂直方向,向右,并按照您的意愿提供右边距。按钮的高度和宽度必须是环绕内容,并在代码中进行以下更改:-LayoutInflater li=getLayoutInflater();
row.addView(li.充气(我们刚刚创建的右布局);
<style name="maxWid">
<item name="android:textStyle">bold|italic</item>
<item name="android:textColor">#FFFFFF</item>
<item name="android:layout_width">fill_parent</item>
</style>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical"
android:layout_weight="1">
<TableLayout
android:id="@+id/tableLayout_1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:shrinkColumns="*"
android:stretchColumns="*"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
>
</TableLayout>
</ScrollView>