简体   繁体   English

Android:拉伸对话框片段布局,说“适应屏幕方向”更改

[英]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? 我应该怎么做呢.....我试图覆盖onConfigurationChange()方法并再次使布局重新膨胀,但是并没有帮助我.....我需要知道如何增加方向改变对话框的面积?

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/ 尝试这样的,你设置你喜欢那里的宽度,我认为,这将帮助你..这里是一个链接,你可以读它,... http://android.programmerguru.com/android-landscape-layout-example /

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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