项目有4个drawable和layout文件夹(xh,h,m,l)。 这是清单的一部分:
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" />
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true" />
这是xhdpi的完整主要xml代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@layout/bg_repeat" >
<RelativeLayout
android:id="@+id/bg_header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="@drawable/bg_header"
android:padding="0dip">
<ImageView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/text_header" />
</RelativeLayout>
<ListView
android:id = "@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="@null"
android:dividerHeight="2.5dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:cacheColorHint="@android:color/transparent"
android:listSelector="@android:color/transparent"
/>
</LinearLayout>
这是xhdpi的行xml:
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout
xmlns:android = "http://schemas.android.com/apk/res/android"
xmlns:foo="http://schemas.android.com/apk/res/test"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingRight="20dp"
android:paddingLeft="20dp">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/menu_selector">
<test.TextViewPlus
android:id="@+id/menutext"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textColor="#3D1E00"
android:textSize="@dimen/TitleNormalXH"
foo:customFont="Mj_Shablon.ttf"
android:gravity="right|center_vertical"/>
</LinearLayout>
</LinearLayout>
这是galaxy note模拟器设置: dpi:285。 android版:google api等级10(2.3.3)
这是输出:
第二个问题:对于行的布局和listview的布局,将android:background =“@ drawable / menu_selector”放在不同之处?
答案 0 :(得分:1)
我想这有助于: 在适配器中,在getView(...)方法中,在给行充气后,使用:
row.setMinimumHeight(height);
方法的参数是pixle你应该选择你特定的dp高度,然后将其转换为px。
答案 1 :(得分:0)
主xml代码:
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/bg_header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:background="@drawable/bg_header">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/text_header" />
</RelativeLayout>
<ListView
android:id = "@+id/mainlist"
style="@style/ListView"
android:dividerHeight="2.5dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
</LinearLayout>
</merge>
行xml代码:
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:dr="http://schemas.android.com/apk/res/pak"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingRight="20dp"
android:paddingLeft="20dp">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/menu_selector"
android:gravity="center">
<pak.TextViewPlus
android:id="@+id/menutext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:textSize="@dimen/TitleNormalM"
android:gravity="right"
dr:customFont="Mj_Shablon.ttf"
android:padding="0dp"/>
</RelativeLayout>
</RelativeLayout>
和九个补丁图像必须类似: