Нужно, чтобы текст оставался слева, а кнопка лепилась справа, как float: right. Как это реализовать?
xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="kg.zuber.pocketlawyer.activities.MyLawsActivity">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="@+id/textView"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button"
android:layout_marginRight="0dp"
android:layout_marginLeft="0dp"
android:layout_weight="0" />
</TableRow>
</TableLayout>
</RelativeLayout>
java: (добавляет такие tableRow в onCreate)
for (int i = 0; i < savedLaws.size(); i++) {
final Law law = savedLaws.get(i);
TableRow tableRow = new TableRow(this);
tableRow.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT,
TableLayout.LayoutParams.WRAP_CONTENT));
TextView lawTitleLabel = new TextView(this);
lawTitleLabel.setText(law.getTitle());
tableRow.addView(lawTitleLabel);
Button deleteButton = new Button(getApplicationContext());
deleteButton.setBackgroundResource(R.drawable.button);
deleteButton.setText("X");
TableRow.LayoutParams rlp = new TableRow.LayoutParams(
TableRow.LayoutParams.MATCH_PARENT,
TableRow.LayoutParams.MATCH_PARENT);
tableRow.setGravity(Gravity.END);
deleteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dbm.deleteLaw(law.getId());
startActivity(new Intent(MyLawsActivity.this, MyLawsActivity.class));
}
});
tableRow.addView(deleteButton);
tableLayout.addView(tableRow, i);
}