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