由网友(傲世あ君临天い)分享简介:我想打开drawerlist到屏幕的一半为所有不同的设备。我用力codeD值layout_margineleft 200dp或100dp到drawerlist。但它不所有设备它不同于设备到设备工作。那么,如何能保持屏幕drawerlist的正好一半。我也尝试过各种功能像setLeft(INT)etc.but有些人不因我...
我想打开drawerlist到屏幕的一半为所有不同的设备。我用力codeD值layout_margineleft 200dp或100dp到drawerlist。但它不所有设备它不同于设备到设备工作。那么,如何能保持屏幕drawerlist的正好一半。我也尝试过各种功能像setLeft(INT)etc.but有些人不因我使用最低版本8,所以,请帮助我的工作。提前致谢。
mDrawerLayout =(DrawerLayout)view.findViewById(R.id.drawer_layout);
mDrawerList =(ListView控件)view.findViewById(R.id.top_sectionlist);
XML为:
< XML版本=1.0编码=UTF-8&GT?;
< android.support.v4.widget.DrawerLayout
的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@ + ID / drawer_layout
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:背景=@色/ setting_background>
< RelativeLayout的的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =FILL_PARENT
机器人:layout_margin =@扪/ top_news_linear_margin
机器人:背景=@色/ news_list_divider_color
机器人:方向=垂直
机器人:填充=@扪/ top_news_linear_padding>
< / RelativeLayout的>
<的ListView
机器人:ID =@ + ID / drawer_list
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =FILL_PARENT
机器人:layout_gravity =右
机器人:layout_alignParentTop =真
机器人:背景=@色/ setting_background
机器人:cacheColorHint =@机器人:彩色/透明
机器人:choiceMode =singleChoice
机器人:分隔=@色/ news_list_divider_color
机器人:dividerHeight =@扪/ news_list_divider_height
/>
< /android.support.v4.widget.DrawerLayout>
解决方案
设置ListView的宽度动态...
mDrawerLayout =(DrawerLayout)view.findViewById(R.id.drawer_layout);
mDrawerList =(ListView控件)view.findViewById(R.id.top_sectionlist);
INT宽度= getResources()getDisplayMetrics()widthPixels / 2。;
DrawerLayout.LayoutParams PARAMS =(android.support.v4.widget.DrawerLayout.LayoutParams)mDrawerList.getLayoutParams();
params.width =宽度;
mDrawerList.setLayoutParams(PARAMS);
I want to open the drawerlist to the half of the screen for all different device. i tried hard coded values for layout_margineleft 200dp or 100dp to the drawerlist. but it doesn't work in all device it different from device to device. so how can i maintain the exactly half of the screen for drawerlist. i also tried various function like setLeft(int) etc.but some of them doesn't work due to i use minimum version 8. So please help me. thanks in advance.
mDrawerLayout = (DrawerLayout) view.findViewById(R.id.drawer_layout);
mDrawerList = (ListView) view.findViewById(R.id.top_sectionlist);
xml for that:
<?xml version="1.0" encoding="utf-8"?>
<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"
android:background="@color/setting_background" >
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_margin="@dimen/top_news_linear_margin"
android:background="@color/news_list_divider_color"
android:orientation="vertical"
android:padding="@dimen/top_news_linear_padding" >
</RelativeLayout>
<ListView
android:id="@+id/drawer_list"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="right"
android:layout_alignParentTop="true"
android:background="@color/setting_background"
android:cacheColorHint="@android:color/transparent"
android:choiceMode="singleChoice"
android:divider="@color/news_list_divider_color"
android:dividerHeight="@dimen/news_list_divider_height"
/>
</android.support.v4.widget.DrawerLayout>
解决方案
set the width for ListView dynamically...
mDrawerLayout = (DrawerLayout) view.findViewById(R.id.drawer_layout);
mDrawerList = (ListView) view.findViewById(R.id.top_sectionlist);
int width = getResources().getDisplayMetrics().widthPixels/2;
DrawerLayout.LayoutParams params = (android.support.v4.widget.DrawerLayout.LayoutParams) mDrawerList.getLayoutParams();
params.width = width;
mDrawerList.setLayoutParams(params);
相关推荐
最新文章