【问题标题】:Android Studio- Rendering Problems: can't find Drawer LayoutAndroid Studio-渲染问题:找不到抽屉布局
【发布时间】:2015-06-02 12:32:55
【问题描述】:

我已经面临这个问题好几天了。 Android studio 无法渲染 DrawerLayout。

我在网上找到了一些类似的问题,但没有一个解决方案对我有用。

我正在使用 Android Studio 1.2.1.1Gradle 1.2.3

我尝试将构建工具更改为 22、21、19。注释对我有用。

我怎样才能让它工作?如果是错误,是否有解决方法?

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.MainScreenActivity">

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <include
        android:id="@+id/toolbar"
        layout="@layout/toolbar" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/facebook_background">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:orientation="vertical">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:src="@drawable/ic_empty_72" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:gravity="center_horizontal"
                android:text="No Polls"
                android:textColor="@color/colorPrimary"
                android:textSize="14sp" />
        </LinearLayout>
    </RelativeLayout>

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/polls_swipe_refresh_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/facebook_background">

        <ListView
            android:id="@+id/polls_listview"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/transparent"
            android:divider="@android:color/transparent"
            android:dividerHeight="10dp"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            android:paddingTop="10dp"
            tools:listitem="@layout/item_poll" />

    </android.support.v4.widget.SwipeRefreshLayout>

    <com.gc.materialdesign.views.ProgressBarCircularIndeterminate
        android:id="@+id/fetchingDataProgressBar"
        android:layout_width="32dp"
        android:layout_height="32dp"
        android:layout_gravity="center"
        android:background="@color/colorPrimary" />

    <com.getbase.floatingactionbutton.FloatingActionButton
        android:id="@+id/submitMain"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="8dp"
        android:layout_marginRight="16dp"
        app:fab_colorNormal="#1E88E5"
        app:fab_colorPressed="#0065BE"
        app:fab_icon="@drawable/ic_add_white_18dp" />

</FrameLayout>

<LinearLayout
    android:id="@+id/left_drawer"
    android:layout_width="280dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="#1E272C"
    android:orientation="vertical">

    <RelativeLayout
        android:id="@+id/navigation_drawer_profileView"
        android:layout_width="match_parent"
        android:layout_height="150dp">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:adjustViewBounds="true"
            android:scaleType="centerCrop"
            android:src="@drawable/nav_drawer_background_orange" />

        <de.hdodenhof.circleimageview.CircleImageView
            android:id="@+id/navigation_drawer_profileImage"
            android:layout_width="72dp"
            android:layout_height="72dp"
            android:layout_marginLeft="16dp"
            android:layout_marginTop="16dp"
            android:src="@drawable/ic_profile_guy_blue"
            app:border_color="@color/white"
            app:border_width="2dp" />

        <TextView
            android:id="@+id/navigation_drawer_userName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/navigation_drawer_profileImage"
            android:layout_marginLeft="16dp"
            android:layout_marginTop="5dp"
            android:text="UserName"
            android:textColor="@color/white"
            android:textSize="14sp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/navigation_drawer_userLevel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/navigation_drawer_userName"
            android:layout_marginLeft="16dp"
            android:text="PickupNoob"
            android:textColor="@color/white"
            android:textSize="14sp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_marginRight="20dp"
            android:layout_marginTop="20dp"
            android:background="#55000000"
            android:padding="10dp"
            android:text="MY PROFILE"
            android:textColor="@color/white"
            android:textSize="16sp"
            android:textStyle="bold" />

    </RelativeLayout>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <TextView
                android:id="@+id/nav_item_login"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/nav_item_background"
                android:clickable="true"
                android:drawableLeft="@drawable/ic_nav_login"
                android:drawablePadding="20dp"
                android:gravity="center_vertical"
                android:padding="16dp"
                android:text="LOGIN / SIGNUP"
                android:textColor="@color/white"
                android:textSize="14sp" />

            <TextView
                android:id="@+id/nav_item_about"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/nav_item_background"
                android:clickable="true"
                android:drawableLeft="@drawable/ic_nav_about"
                android:drawablePadding="20dp"
                android:gravity="center_vertical"
                android:padding="16dp"
                android:text="ABOUT"
                android:textColor="@color/white"
                android:textSize="14sp" />

            <TextView
                android:id="@+id/nav_item_donate"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/nav_item_background"
                android:clickable="true"
                android:drawableLeft="@drawable/ic_nav_donate"
                android:drawablePadding="20dp"
                android:gravity="center_vertical"
                android:padding="16dp"
                android:text="DONATE"
                android:textColor="@color/white"
                android:textSize="14sp" />

            <TextView
                android:id="@+id/nav_item_rate"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/nav_item_background"
                android:clickable="true"
                android:drawableLeft="@drawable/ic_nav_rate"
                android:drawablePadding="20dp"
                android:gravity="center_vertical"
                android:padding="16dp"
                android:text="RATE THE APP"
                android:textColor="@color/white"
                android:textSize="14sp" />

            <TextView
                android:id="@+id/nav_item_feedback"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/nav_item_background"
                android:clickable="true"
                android:drawableLeft="@drawable/ic_nav_feedback"
                android:drawablePadding="20dp"
                android:gravity="center_vertical"
                android:padding="16dp"
                android:text="FEEDBACK"
                android:textColor="@color/white"
                android:textSize="14sp" />

            <TextView
                android:id="@+id/nav_item_logout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/nav_item_background"
                android:clickable="true"
                android:drawableLeft="@drawable/ic_nav_logout"
                android:drawablePadding="20dp"
                android:gravity="center_vertical"
                android:padding="16dp"
                android:text="LOGOUT"
                android:textColor="@color/white"
                android:textSize="14sp" />
        </LinearLayout>
    </ScrollView>
</LinearLayout>

【问题讨论】:

    标签: android android-studio android-gradle-plugin android-support-library


    【解决方案1】:

    尝试在您的设计器预览中更改您的 android 版本,即呈现您的 xml.

    【讨论】:

    • 它适用于普通视图。只是不适用于支持 v4 小部件。我尝试了所有版本,但没有使用任何版本。
    • 嗨,我已经用布局 xml 代码更新了问题。顺便说一句,您能否指定您的 android studio 版本、gradle 版本、Buildtool 版本等。也可能是因为系统映像。您使用哪个系统映像进行渲染?
    猜你喜欢
    • 1970-01-01
    • 2014-08-20
    • 1970-01-01
    • 1970-01-01
    • 2019-09-10
    • 2021-09-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多