0

画像ボタンの背景に設定している独自の描画可能オブジェクトを作成しました。(ここに記載)

<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="oval">
    <solid android:color="#A7BF1D"/> </shape>

これらを画面の横に垂直方向に均等に配置したいので、android:layout_weight を使用してこれを実現します。(ここに記載)

<LinearLayout 
        android:id="@+id/left_bar"
        android:orientation="vertical"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:layout_weight="8">
        <Button
            android:id="@+id/btnCall"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_gravity="1"
            android:background="@drawable/btn_circle"            
            android:text="Call"
            android:textSize="12sp" />
       <Space
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_gravity="1"></Space>
        <Button
            android:id="@+id/btnSpeak"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_gravity="1"
            android:background="@drawable/btn_circle"
            android:text="Speak"
            android:textSize="12sp" />
       <Space
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_gravity="1"></Space>
        <Button
            android:id="@+id/btnRecordedMessage"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_gravity="1"
            android:background="@drawable/btn_circle"
            android:text="Recorded Message"
            android:textSize="12sp" />
        <Space
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_gravity="1"></Space>
        <Button
            android:id="@+id/btnSelectAll"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_gravity="1"
            android:background="@drawable/btn_circle"
            android:text="Select All Units"
            android:textSize="12sp" />
       <Space
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_gravity="1"></Space>
        <Button
            android:id="@+id/btnDeselectUnits"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_gravity="1"
            android:background="@drawable/btn_circle"
            android:text="Deselect Units"
            android:textSize="12sp" />
        <Space
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_gravity="1"></Space>
        <Button
            android:id="@+id/btnAnswer"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_gravity="1"
            android:background="@drawable/btn_circle"
            android:text="Answer"
            android:textSize="12sp" />
    </LinearLayout>

私が何をしても、それらのそれぞれに合わせてスケーリングすることはもちろん、どの画面サイズでも均等に配置することはできないようです。私の問題は、円を形成するために高さと幅を指定する必要があることだと思いますが、それを行うとすぐに、(より良い用語が必要なため)「ハードコーディング」されているため、layout_weight が台無しになります。

画面の下に均等に配置された6つの円形ボタンの垂直レイアウトを作成することは可能だと思いますが、どうすれば解決できませんか? なしでも試してみましたが、代わりに<Space>パディングを追加しました。<Button>

ここに画像の説明を入力 ここに画像の説明を入力

4

3 に答える 3

0

良い。1 つは、LinearLayouts の子のすべての layout_widths が match_parent に設定されていることです。最初の子がレンダリングされた後は、すべてのスペースを占有するため、他のものを入れる余地はありません。

次に、すべてのタグを使用しないことを強くお勧めします。代わりに、ボタンのパディング (またはマージン) を設定するだけです。

于 2013-07-24T01:20:53.030 に答える
0

私の理解が正しければ、View内の s のLinearLayout間隔をweight. もしそうなら、ではなく、android:layout_weightそれぞれにあるはずです。theには the があり、 eachにはof と言って 1 があります。ViewLinearLayoutLinearLayoutandroid:weightSumViewweightweightSum

<LinearLayout 
    android:id="@+id/left_bar"
    android:orientation="vertical"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:layout_weight="8">  // Try removing this and add weights to your views

これで問題が解決するかどうかはわかりませんが、それから始めます

于 2013-07-24T01:21:05.650 に答える
0

私も同じ問題を抱えていました。等間隔の水平 LinearLayout に 4 つの円形ボタンを配置する必要がありました。

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginBottom="10dp" >

        <Button
            android:id="@+id/btn1"
            style="@style/BotonCircular"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.2"
            android:background="@drawable/boton_circulo_negro" />
        <View 
            android:layout_weight="0.033"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            />

        <Button
            android:id="@+id/btn2"
            style="@style/BotonCircular"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.2"
            android:background="@drawable/boton_circulo_negro" />
        <View 
            android:layout_weight="0.033"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            />
        <Button
            android:id="@+id/btn3"
            style="@style/BotonCircular"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.2"
            android:background="@drawable/boton_circulo_negro" />
        <View 
            android:layout_weight="0.033"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            />
        <Button
            android:id="@+id/btn4"
            style="@style/BotonCircular"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.2"
            android:background="@drawable/boton_circulo_negro" />

    </LinearLayout>

そして、それらをすべて同じ高さにするために、このコードをアクティビティの onCreate 内に配置しました

final Button btn1 = (Button) findViewById(R.id.btn1);
final Button btn2 = (Button) findViewById(R.id.btn2);
final Button btn3 = (Button) findViewById(R.id.btn3);
final Button btn4 = (Button) findViewById(R.id.btn4);
ViewTreeObserver vto = btn1.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

    @Override
    public void onGlobalLayout() {
        btn1.setHeight(btn1.getWidth()); 
        btn2.setHeight(btn1.getWidth());    
        btn3.setHeight(btn1.getWidth());
        btn4.setHeight(btn1.getWidth());
    }
});

これが同じ問題を抱えている人に役立つことを願っています。

于 2013-09-13T18:27:47.440 に答える