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

时间:2013-03-14 11:58:49

标签: android android-fragments android-activity android-dialogfragment android-orientation

我有一个Dialog片段,当这个片段中的布局膨胀时:

当我更改此屏幕的方向时,对话框会缩小,看起来好像它被强制适应横向模式并且不适合屏幕以适当的比例。我应该怎么做..... 我尝试重写onConfigurationChange()方法并再次重新定义布局,但没有帮助我..... 我需要知道如何增加方向更改对话框的区域?

这是我的布局:

<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>

这是我的Dialog片段:

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));
    }
}

任何帮助都非常重要。

1 个答案:

答案 0 :(得分:0)

我认为您应该为横向配置创建布局。尝试这样,并设置你喜欢的宽度,我认为这将有助于你..这是一个链接,你可以阅读,... http://android.programmerguru.com/android-landscape-layout-example/