在所有分辨率设备android中维护文本大小的问题

时间:2014-07-26 09:28:11

标签: android android-layout layout text-size

你好朋友我有一个布局是我的列表项 三星Galaxy Grad Quatrro 看起来如下

enter image description here

HTC欲望V 中,它看起来如下所示

enter image description here

对于两个设备,我使用相同的布局文件,如下所示

row.xml

<RelativeLayout
    android:id="@+id/rel_tops"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:background="@android:color/white"
    android:paddingLeft="10dp"
    android:paddingRight="10dp" >

    <RelativeLayout
        android:id="@+id/rel_imgss"
        android:layout_width="133px"
        android:layout_height="123px" >

        <ImageView
            android:id="@+id/img"
            android:layout_width="133px"
            android:layout_height="123px"
            android:layout_alignParentLeft="true"
            android:background="@drawable/rect_image_border"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:padding="2dp"
            android:scaleType="fitXY"
            android:src="@drawable/no_image" />

        <ImageView
            android:id="@+id/img_pro_status"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:src="@drawable/available_rbn" />
    </RelativeLayout>

    <TextView
        android:id="@+id/roe_pro_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="2dp"
        android:layout_marginLeft="5dp"
        android:layout_toRightOf="@+id/rel_imgss"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:text=""
        android:singleLine="true"
        android:ellipsize="end"
        android:textColor="#343434"
        android:textSize="18sp" />

    <TextView
        android:id="@+id/roe_pro_rent_txt"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/roe_pro_name"
        android:layout_below="@+id/roe_pro_name"
        android:layout_centerVertical="true"
        android:layout_toRightOf="@+id/rel_imgss"
        android:drawablePadding="5dp"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:text="Rented : "
        android:singleLine="true"
        android:ellipsize="end"
        android:textColor="#686868"
        android:textSize="13sp"
        android:visibility="visible" />

    <TextView
        android:id="@+id/txt_view_detail"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/roe_pro_name"
        android:layout_below="@+id/roe_pro_rent_txt"
        android:text="DETAIL"
        android:textColor="#686868"
        android:singleLine="true"
        android:ellipsize="end"
        android:textSize="13sp"
        android:visibility="visible" />

    <TextView
        android:id="@+id/roe_pro_rent"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/roe_pro_name"
        android:layout_below="@+id/roe_pro_name"
        android:layout_marginBottom="2dp"
        android:layout_marginTop="2dp"
        android:layout_toRightOf="@+id/rel_imgss"
        android:ellipsize="end"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:singleLine="true"
        android:text=""
        android:textSize="15sp"
        android:textColor="#282828"
        android:visibility="gone" />

     <View
        android:id="@+id/v_up"
        android:layout_width="fill_parent"
        android:visibility="gone"
        android:layout_height="1dp"
         android:layout_toRightOf="@+id/rel_imgss"
        android:layout_above="@+id/rel_botoom"
        android:background="#e2e2e2" />
    <LinearLayout
        android:id="@+id/rel_botoom"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/rel_imgss"
        android:layout_toRightOf="@+id/rel_imgss"
        android:background="#f4f4f4"
        android:gravity="bottom"
        android:orientation="horizontal"
        android:weightSum="100" >

        <TextView
            android:id="@+id/roe_pro_bed"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="20"
            android:drawableLeft="@drawable/badroom_icon"
            android:drawablePadding="2dp"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:gravity="center"
            android:padding="5dp"
            android:text="12"
            android:textColor="#282828"
            android:textSize="12sp" />

        <View
            android:layout_width="1dp"
            android:layout_height="fill_parent"
            android:background="#e8e8e8" />

        <TextView
            android:id="@+id/roe_pro_bath"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="20"
            android:drawableLeft="@drawable/bathroom_icon"
            android:drawablePadding="2dp"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:gravity="center"
            android:padding="5dp"
            android:text="34"
            android:textColor="#282828"
            android:textSize="12sp" />

        <View
            android:layout_width="1dp"
            android:layout_height="fill_parent"
            android:background="#e8e8e8" />

        <TextView
            android:id="@+id/roe_pro_area"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="35"
            android:drawableLeft="@drawable/sqsize_icon"
            android:drawablePadding="2dp"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:gravity="center"
            android:padding="5dp"
            android:text="1222 sqft"
            android:textColor="#282828"
            android:textSize="12sp" />

        <View
            android:layout_width="1dp"
            android:layout_height="fill_parent"
            android:background="#e8e8e8" />

        <TextView
            android:id="@+id/roe_pro_unit"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="25"
            android:drawableRight="@drawable/unit_dropdown"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:gravity="center"
            android:padding="5dp"
            android:text="Unit 01"
            android:textColor="#282828"
            android:textSize="12sp" />
    </LinearLayout>



</RelativeLayout>

对于上面的代码,它在三星Galaxy Gran Quatroo 中运行良好,但 HTC desire V 并且 textsize 无法正常运行这两个设备怎么解决这个问题?

1 个答案:

答案 0 :(得分:0)

问题是您使用 px 而不是 dp 作为layout_width和layout_height单位。将px更改为dp。 更新

检查fontsize的设备设置。因为一个设备可能有大而其他小的导致问题。可以在Settings-&gt; Display-&gt; Font Size

中找到这些设置