Android 在 drawerlayout 的 listview 底部添加 textview
Android add textview at the bottom of listview in drawerlayout
我的布局包含一个带有片段容器和列表视图的抽屉布局。列表视图包含三个项目,我用适配器添加了这些项目。
<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">
<!-- Framelayout to display Fragments -->
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- Listview to display slider menu -->
<ListView
android:id="@+id/list_slidermenu"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@drawable/listview_background_drawable"
android:listSelector="@android:color/transparent"
android:cacheColorHint="@android:color/transparent"/>
</android.support.v4.widget.DrawerLayout>
所以现在我想在列表视图(屏幕)的底部添加一个视图。我尝试使用 addFooterView(),但这只是将视图添加到最后一项下,而不是在屏幕底部。我现在有几个关于 Whosebug 的例子,但是它们对我不起作用,因为我的抽屉布局。
有没有办法将视图添加到我的列表视图并将视图对齐到屏幕底部?
将您的抽屉设置为布局,并将列表和其他视图放入其中。例如:
<!-- Listview to display slider menu -->
<LinearLayout
android:id="@+id/list_slidermenu"
android:layout_width="240dp"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:id="@+id/lvList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:background="@drawable/listview_background_drawable"
android:listSelector="@android:color/transparent"
android:cacheColorHint="@android:color/transparent"/>
<TextView
android:id="@+id/tvText"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
在这种情况下,底部布局应该从ListView
中取出。您需要将所有元素包含在父布局中(最好是 RelativeLayout
)并在其中声明 DrawerLayout
和底部布局。此外,为底部布局设置 android:layout_alignParentBottom="true",使其始终保持在底部。
示例:
<RelativeLayout
...
... >
(put your drawer layout xml here)
<BottomLayout
android:layout_alignParentBottom="true" >
</BottomLayout>
</RelativeLayout>
滑块菜单可以是任何类型的视图,因此您可以制作如下内容:
<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">
<!-- Framelayout to display Fragments -->
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- Listview to display slider menu -->
<LinearLayout
android:id="@+id/slidermenu"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start">
<ListView
android:id="@+id/list_slidermenu"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@drawable/listview_background_drawable"
android:listSelector="@android:color/transparent"
android:cacheColorHint="@android:color/transparent"/>
<TextView
android:id="@+id/text_slidermenu"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
您可以通过将布局作为页脚视图添加到列表视图或使用此代码将页眉更改为页脚来执行此操作。
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
<RelativeLayout
android:id="@+id/slider"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start" >
<LinearLayout
android:id="@+id/header_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#AA000000"
android:orientation="horizontal"
android:padding="5dp" >
<com.wholesaleraja.model.RoundImage
android:id="@+id/profile_icon"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_gravity="center_vertical"
android:padding="5dp"
android:src="@drawable/default_image_male" />
<LinearLayout
android:id="@+id/profile_name_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="vertical"
android:padding="5dp" >
<TextView
android:id="@+id/profile_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textColor="#ffffff"
android:textSize="20sp" />
<TextView
android:id="@+id/profile_email"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:textSize="12sp" />
</LinearLayout>
</LinearLayout>
<View
android:id="@+id/header_divider"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:layout_below="@+id/header_view"
android:background="@color/list_divider" />
<ListView
android:id="@+id/list_slidermenu"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_below="@+id/header_divider"
android:background="@color/list_header"
android:choiceMode="singleChoice"
android:divider="@color/list_divider"
android:dividerHeight="1dp"
android:overScrollMode="never" />
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
我的布局包含一个带有片段容器和列表视图的抽屉布局。列表视图包含三个项目,我用适配器添加了这些项目。
<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">
<!-- Framelayout to display Fragments -->
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- Listview to display slider menu -->
<ListView
android:id="@+id/list_slidermenu"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@drawable/listview_background_drawable"
android:listSelector="@android:color/transparent"
android:cacheColorHint="@android:color/transparent"/>
</android.support.v4.widget.DrawerLayout>
所以现在我想在列表视图(屏幕)的底部添加一个视图。我尝试使用 addFooterView(),但这只是将视图添加到最后一项下,而不是在屏幕底部。我现在有几个关于 Whosebug 的例子,但是它们对我不起作用,因为我的抽屉布局。
有没有办法将视图添加到我的列表视图并将视图对齐到屏幕底部?
将您的抽屉设置为布局,并将列表和其他视图放入其中。例如:
<!-- Listview to display slider menu -->
<LinearLayout
android:id="@+id/list_slidermenu"
android:layout_width="240dp"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:id="@+id/lvList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:background="@drawable/listview_background_drawable"
android:listSelector="@android:color/transparent"
android:cacheColorHint="@android:color/transparent"/>
<TextView
android:id="@+id/tvText"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
在这种情况下,底部布局应该从ListView
中取出。您需要将所有元素包含在父布局中(最好是 RelativeLayout
)并在其中声明 DrawerLayout
和底部布局。此外,为底部布局设置 android:layout_alignParentBottom="true",使其始终保持在底部。
示例:
<RelativeLayout
...
... >
(put your drawer layout xml here)
<BottomLayout
android:layout_alignParentBottom="true" >
</BottomLayout>
</RelativeLayout>
滑块菜单可以是任何类型的视图,因此您可以制作如下内容:
<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">
<!-- Framelayout to display Fragments -->
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- Listview to display slider menu -->
<LinearLayout
android:id="@+id/slidermenu"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start">
<ListView
android:id="@+id/list_slidermenu"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@drawable/listview_background_drawable"
android:listSelector="@android:color/transparent"
android:cacheColorHint="@android:color/transparent"/>
<TextView
android:id="@+id/text_slidermenu"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
您可以通过将布局作为页脚视图添加到列表视图或使用此代码将页眉更改为页脚来执行此操作。
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
<RelativeLayout
android:id="@+id/slider"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start" >
<LinearLayout
android:id="@+id/header_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#AA000000"
android:orientation="horizontal"
android:padding="5dp" >
<com.wholesaleraja.model.RoundImage
android:id="@+id/profile_icon"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_gravity="center_vertical"
android:padding="5dp"
android:src="@drawable/default_image_male" />
<LinearLayout
android:id="@+id/profile_name_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="vertical"
android:padding="5dp" >
<TextView
android:id="@+id/profile_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textColor="#ffffff"
android:textSize="20sp" />
<TextView
android:id="@+id/profile_email"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:textSize="12sp" />
</LinearLayout>
</LinearLayout>
<View
android:id="@+id/header_divider"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:layout_below="@+id/header_view"
android:background="@color/list_divider" />
<ListView
android:id="@+id/list_slidermenu"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_below="@+id/header_divider"
android:background="@color/list_header"
android:choiceMode="singleChoice"
android:divider="@color/list_divider"
android:dividerHeight="1dp"
android:overScrollMode="never" />
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>