我有一个listView它在真实设备中查看得很好但是当我在模拟器中运行它时它会在右边有一个空格
这是我的布局列表代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="12dp"
android:orientation="horizontal" >
<ListView
android:id="@+id/tipList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/buttons"
android:divider="#C0C0C0"
android:dividerHeight="2px"
android:choiceMode="singleChoice"
android:listSelector="@drawable/list_selector" />
</LinearLayout>
行项目的代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@drawable/tip_list_selector">
<TextView
android:id="@+id/tip_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="50dp"
android:layout_marginLeft="2dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:maxLines="2"
android:ellipsize="end"
android:text="Rihanna Love the way lieger jlgfi rehjglirejhgoljg rijgjre jgorejg jgjreo ijgoir gjro gjorjgo gjoirjgoirej gjogijrog joir oirjgojre"
android:textColor="#4f4f4f"
android:textSize="20sp" />
<ImageView
android:id="@+id/favorite_star"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="3dp"
android:background="@drawable/tips_star_off" />
提示: listView位于Fragment ..
中activity_main代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<LinearLayout
android:id="@+id/titleBar"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentTop="true"
android:background="@color/tip_background"
android:orientation="horizontal" >
<ImageButton
android:id="@+id/iconImg"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_margin="5dip"
android:background="@drawable/header_logo" />
<LinearLayout
android:id="@+id/actionBarBtns"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:layout_weight="1"
android:layout_marginRight="10dp"
android:gravity="right"
android:orientation="horizontal" >
<RelativeLayout
android:id="@+id/search_tip_rl"
android:layout_width="wrap_content"
android:layout_marginRight="20dp"
android:layout_height="60dp" >
<ImageButton
android:id="@+id/search_tip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="gone"
android:background="@drawable/header_search"
/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/add_tip_rl"
android:layout_width="wrap_content"
android:layout_marginRight="20dp"
android:layout_height="60dp">
<ImageButton
android:id="@+id/add_tip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="gone"
android:background="@drawable/header_add"
/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/count_tip_rl"
android:layout_width="wrap_content"
android:layout_height="60dp">
<ImageButton
android:id="@+id/count_tip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginRight="5dp"
android:visibility="gone"
android:background="@drawable/header_count" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
<EditText
android:id="@+id/inputSearch"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawableLeft="@android:drawable/ic_menu_search"
android:hint="Search Tips"
android:inputType="textVisiblePassword"
android:visibility="gone"
android:imeOptions="actionSearch"
android:layout_below="@+id/titleBar" />
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_below="@+id/inputSearch" />
<!-- parts slider -->
<com.slidinglayer.SlidingLayer
xmlns:slidingLayer="http://schemas.android.com/apk/res/emy.dt4it.healthytips"
android:id="@+id/slidingLayer1"
android:layout_width="@dimen/left_layer_width"
android:layout_height="match_parent"
slidingLayer:stickTo="left"
slidingLayer:closeOnTapEnabled="true"
android:layout_marginTop="60dp"
slidingLayer:shadowWidth="@dimen/shadow_width"
slidingLayer:offsetWidth="@dimen/offset_width">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/list_background">
<ListView
android:id="@+id/list_slidermenu"
android:layout_width="220dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#C0C0C0"
android:dividerHeight="2px"
android:listSelector="@drawable/list_selector" />
</RelativeLayout>
</com.slidinglayer.SlidingLayer>
<com.slidinglayer.SlidingLayer
xmlns:slidingLayer="http://schemas.android.com/apk/res/emy.dt4it.healthytips"
android:id="@+id/slidingLayer2"
android:layout_marginTop="60dp"
android:layout_width="@dimen/right_layer_width"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/tip_background">
<include layout="@layout/tip_details" android:id="@+id/include1" />
</RelativeLayout>
</com.slidinglayer.SlidingLayer>
</RelativeLayout>
我用以下代码打开它:
Fragment fragment = new TipsFragment(1,0, START_FROM);
if (fragment != null) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.frame_container,fragment);
ft.addToBackStack(null);
ft.commit();
// update selected item and title, then close the drawer
mDrawerList.setItemChecked(position, true);
mDrawerList.setSelection(position);
setTitle(navMenuTitles[position]);
} else {
// error in creating fragment
Log.e("MainActivity", "Error in creating fragment");
}
答案 0 :(得分:0)
尝试用这个替换行项目的布局。这个应该有用。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/tip_list_selector">
<ImageView
android:id="@+id/favorite_star"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="3dp"
android:background="@drawable/tips_star_off" />
<TextView
android:id="@+id/tip_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/favorite_star"
android:paddingRight="5dp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:maxLines="2"
android:ellipsize="end"
android:text="Rihanna Love the way lieger jlgfi rehjglirejhgoljg rijgjre jgorejg jgjreo ijgoir gjro gjorjgo gjoirjgoirej gjogijrog joir oirjgojre"
android:textColor="#4f4f4f"
android:textSize="20sp" />
TextView现在位于ImageView的左侧,并匹配剩余的宽度。
答案 1 :(得分:0)
似乎您在activity_main.xml中使用了固定宽度的listview。
<ListView
android:id="@+id/list_slidermenu"
android:layout_width="220dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#C0C0C0"
android:dividerHeight="2px"
android:listSelector="@drawable/list_selector" />
变化
android:layout_width="220dp"
到
android:layout_width="fill_parent"
答案 2 :(得分:-1)
我有类似的问题。原因是图像大小,尝试将imageView添加到此:android:scaleType="fitXY"