繁体   English   中英

Android自定义布局作为导航抽屉

[英]Android custom layout as navigation drawer

我正在尝试使用ArrayAdapter构建具有许多元素的标准简单navigation drawer ,但是当单击元素时,我需要将一些html加载到抽屉内的webView ,这可能以某种方式吗? 预期抽屉结构

我为此而建立了这样的layou

 <?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_new_order"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".BaseActivity">

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

        <include layout="@layout/app_bar" />

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

            <include layout="@layout/activity_content_base" />

        </FrameLayout>
    </LinearLayout>

    <!--place for drawer-->
    <FrameLayout
        android:id="@+id/navWeb"
        android:layout_width="250dp"
        android:layout_height="match_parent"
        android:layout_gravity="right|end">

        <include layout="@layout/drawer_test" />

    </FrameLayout>

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

这里的layout/drawer_test是我的cutom layout

尝试这个:-

替换此代码(在代码中的正确位置):

<LinearLayout
        android:id="@+id/drawer_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:layout_margin="1dp"
        android:background="@drawable/rounded_corner"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="10dp"
            android:background="@drawable/rectangle"
            android:orientation="horizontal"
            android:weightSum="100">

            <ListView
                android:id="@+id/drawerList"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="50"
                android:choiceMode="singleChoice"
                android:listSelector="@drawable/list_selector" />

            <WebView
                android:id="@+id/webview"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="50"
                android:background="#888888" />
        </LinearLayout>
    </LinearLayout>

创建2个可绘制对象rectangle.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <solid android:color="#ffffff"/>

    <stroke
        android:width="4dp"
        android:color="@android:color/holo_red_light"/>

    <padding
        android:bottom="5dp"
        android:left="5dp"
        android:right="5dp"
        android:top="5dp"/>

</shape>

和rounded_corner.xml

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle"   >

    <solid
        android:color="#ffffff" >
    </solid>

    <stroke
        android:width="4dp"
        android:color="@android:color/holo_red_light" >
    </stroke>

    <padding
        android:left="5dp"
        android:top="5dp"
        android:right="5dp"
        android:bottom="5dp"    >
    </padding>

    <corners
        android:radius="10dp"   >
    </corners>

</shape>

暂无
暂无

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

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