ボタンを ListActivity に動的に追加しています。次のように:
setContentView(R.layout.listview_singlegrey);
LayoutInflater inflater = (LayoutInflater)this.getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout linear = (LinearLayout) findViewById(R.id.list_comment);
Button btAddComment = (Button)inflater.inflate(R.layout.bt_yellow,null);
FrameLayout.LayoutParams lyp1 = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
lyp1.gravity = Gravity.RIGHT;
btAddComment.setLayoutParams(lyp1);
btAddComment.setText("Añadir comentario");
リストビューの LinearLayout は次のとおりです。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:orientation="vertical"
android:layout_height="fill_parent" android:id="@+id/list_comment"
android:paddingLeft="10dp" android:paddingRight="10dp" android:background="@drawable/fondomain">
<ListView android:id="@+id/android:list" android:listSelector="@android:color/transparent"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:divider="@layout/linedivider" android:dividerHeight="10px"
android:cacheColorHint="#0000" android:paddingTop="10dp"
/>
</LinearLayout>
そして、私が膨らませているところからのボタンのレイアウトは次のとおりです。
<?xml version="1.0" encoding="utf-8"?>
<Button xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/wrapfill"
android:background="@layout/selectoryellowbutton" android:layout_gravity="right" android:padding="10dp"
android:textSize="16px" android:text="Añadir comentario" android:textStyle="bold" android:textColor="@color/darkergray">
</Button>
ご覧のとおり、コードとボタンで layout_gravity パラメータを設定しようとしましたが、どれも機能しません。私はまだ画面の左側にボタンを表示しています。レイアウト パラメータが機能していないようです。しかし、幅にfill_parentを設定すると、画面全体にボタンが表示され、テキストを折り返して画面の右側に配置するボタンが必要になります。