简体   繁体   中英

Android: Stretch the dialog fragment layout say Fit To Screen on Orientation change

I have a Dialog Fragment and when the layout in this fragment is inflated:

When i change the orientation of this screen the dialog gets condensed and looks as if its forced to fit in the landscape mode and doesn't fit to screen in appropriate proportion. How mi supposed to do it..... i tried overriding the onConfigurationChange() method and reinflating the layout again, but didnt help me..... I need to know how to increase the area of a dialog on orientation change?

This is my Layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="4dip"
android:background="@drawable/techdeals_tip_screen" >



<Button
    android:id="@+id/show"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:layout_weight="0"
    android:background="@android:color/transparent" 
    android:layout_gravity="right">

    <requestFocus />
</Button>

This is my Dialog Fragment :

public static class MyDialogFragment extends SherlockDialogFragment {


    /**
     * Create a new instance of MyDialogFragment.
     */
    static MyDialogFragment newInstance() {
MyDialogFragment f = new MyDialogFragment();
        return f;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Pick a style based on the num.
        int style = DialogFragment.STYLE_NO_TITLE;
        int theme = 0;
        setStyle(style, theme);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_tips_dialog, container, false);
        Button button = (Button)v.findViewById(R.id.show);
        button.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                dismiss();
            }
        });
        return v;
    }

    @Override
    public void onStop() {
        super.onStop();
        final Activity activity = getActivity();
        launchNextScreen(getActivity());
        activity.finish();
    }

    /** Method to launch home screen after tip screen. */
    private void launchNextScreen(Activity activity) {
        setViewedWelcomeScreen(activity);
        activity.startActivity(new Intent(activity, HomeTabActivity.class));
    }
}

Any help will be of great importance.

i think you should create layout for your landscape config. try like that and set you the width you like there, i think that will help you.. here is a link, you can read it, ... http://android.programmerguru.com/android-landscape-layout-example/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM