Navigation Drawer rendering error in ADT Layout Editor

扶醉桌前 提交于 2019-11-29 02:52:11
Asmok

I have similar problem. If you want preview layout for a moment, you can temporally change the width and height to absolute.

eg:-

<android.support.v4.widget.DrawerLayout

    xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="400px"

    android:layout_height="800px">

This is fixed in version 18 of the support library, released in July.

in Eclipse right click your project > select android tools > add support library.

Fixed. :)

joecks

From another Question I solved the problem by extending DrawerLayout, and forcing the correct Measure_Specs:

public class CustomDrawerLayout extends DrawerLayout {

    public CustomDrawerLayout(Context context) {
        super(context);
    }

    public CustomDrawerLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomDrawerLayout(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        widthMeasureSpec = MeasureSpec.makeMeasureSpec(
                MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.EXACTLY);
        heightMeasureSpec = MeasureSpec.makeMeasureSpec(
                MeasureSpec.getSize(heightMeasureSpec), MeasureSpec.EXACTLY);
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

}

Asmok's answer is nice but I'm this type of person always forgetting to reverse such "temporary" edits. (In other words temporary may become very big ^^)

So instead I use the <include> tag and split the layout in two files.

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- The main content view -->
    <include layout="@layout/main_layout" />

    <!-- The navigation drawer -->
    <include layout="@layout/navigation_drawer"/>
</android.support.v4.widget.DrawerLayout>

For the main layout (which is the UI of the activit in question) I can now use Eclipse's graphical editor as all the content lives in a single file main_layout.xml.
Furthermore I can easily include the navigation drawer in different activities without the need to copy and paste the code.

Walterjp

The easiest solution I found was to put in the preview Theme.Holo.Light.Dialog.FixedSize functional and peaceful ...

Custom Views are difficult to display correctly for the UI editor in eclipse (same goes for the UI editor in Android Studio). This is normal.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!