1

幅に沿って match_parent する必要があるダイアログ/モーダルがあります。ただし、wrap_content を実行し続けます。これを修正する方法はありますか?

これが私のレイアウトです

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/my_root"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:background="#55555555" >

        <Button
            android:id="@+id/dogs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:background="#AAAAAA"
            android:clickable="true"
            android:gravity="center"
            android:onClick="onDogsClicked"
            android:text="Dogs" />

        <Button
            android:id="@+id/cats"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:background="#AAAAAA"
            android:clickable="true"
            android:gravity="center"
            android:onClick="Cats"
            android:text="Cat" />

        <Button
            android:id="@+id/snake"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:background="#FF0000"
            android:clickable="true"
            android:gravity="center"
            android:onClick="onSnakeClicked"
            android:text="Snake" />

        <Button
            android:id="@+id/sheep"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:background="#AAAAAA"
            android:clickable="true"
            android:gravity="center"
            android:onClick="onSheepClicked"
            android:text="Sheep" />
    </LinearLayout>

</LinearLayout>

ここにプログラムの断片があります

Dialog animalsView;

    public void onAnimalsClicked(View v) {

        LayoutInflater inflater = getLayoutInflater();
        View dialoglayout = inflater.inflate(R.layout.animals_layout,
            (ViewGroup) findViewById(R.id.my_root));

        animalsView = new Dialog(this, R.style.CustomDialog);
        WindowManager.LayoutParams wmlp = animalsView.getWindow()
            .getAttributes();

        wmlp.gravity = Gravity.BOTTOM;
        wmlp.flags &= ~WindowManager.LayoutParams.FLAG_DIM_BEHIND;
        animalsView.getWindow().setAttributes(wmlp);

        animalsView.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        animalsView.setContentView(dialoglayout);
        animalsView.getWindow().setBackgroundDrawable(new ColorDrawable(0));
        animalsView.show();
    }
4

4 に答える 4

1

これを試して...

public void onAnimalsClicked(View v) {

    LayoutInflater inflater = getLayoutInflater();
    View dialoglayout = inflater.inflate(R.layout.animals_layout,
        (ViewGroup) findViewById(R.id.my_root));

    animalsView = new Dialog(this, R.style.CustomDialog);

    ........

    animalsView.setContentView(dialoglayout);

    animalsView.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);

    ......

    animalsView.show();
}
于 2015-02-27T05:40:40.460 に答える