ボタン付きの垂直メニューを作成しようとしています。そのため、垂直線形レイアウトを作成し、ボタンをプログラムで追加しています。問題は、すべてのボタンが同じサイズ (テキストが最も長いボタンのサイズ) になっていることです。それらを異なるサイズで中央に配置したいと思います。それ、どうやったら出来るの?
私のボタンのレイアウト:
<Button xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/big_button"
style="@style/button_style" >
</Button>
私の活動のレイアウト:
<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">
<ImageView
android:id="@+id/appLogo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:src="@drawable/logo" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@id/appLogo">
<LinearLayout
android:id="@+id/startLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
</RelativeLayout>
ボタンはプログラムで作成されます。
Button cityButton = (Button) getLayoutInflater().inflate(R.layout.city_button, null);
cityButton.setText(title);
cityButton.setId(id);
ボタンのスタイル:
<style name="button_style" >
<item name="android:layout_width" >wrap_content</item>
<item name="android:layout_height" >wrap_content</item>
<item name="android:textColor" >@drawable/button_text_color</item>
<item name="android:gravity" >center</item>
<item name="android:textSize" >30dp</item>
</style>