现在的位置: 首页 > 移动开发 > 正文

Android5.0中TextVIew布局设置和5.0以前的冲突

2018年09月19日 移动开发 ⁄ 共 2851字 ⁄ 字号 评论关闭

同一个布局文件,Android5.0以下的都可以显示

而Android5.0显示不了文字

布局文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:orientation="vertical">



    <View

        android:layout_width="fill_parent"

        android:layout_height="1px"

        android:layout_marginTop="14dp"

        android:background="@color/abc_search_url_text_pressed"/>



    <RelativeLayout

        android:id="@+id/lay_coupons"

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:layout_marginBottom="14dp"

        android:visibility="visible">



        <TextView

            android:id="@+id/tv_coupons"

            android:layout_width="fill_parent"

            android:layout_height="wrap_content"

            android:layout_margin="12dp"

            android:drawablePadding="10dp"

            android:drawableRight="@android:drawable/checkbox_off_background"

            android:gravity="right"

            android:text="1个"/>



        <TextView

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_marginBottom="12dp"

            android:layout_marginLeft="16dp"

            android:layout_marginRight="10dp"

            android:layout_marginTop="12dp"

            android:layout_toLeftOf="@id/tv_coupons"

            android:text="我的收藏"

            android:textColor="@color/abc_search_url_text_holo"

            android:textSize="16sp"/>

    </RelativeLayout>



    <View

        android:layout_width="fill_parent"

        android:layout_height="1px"

        android:layout_below="@id/tv_coupons"

        android:background="@color/abc_search_url_text_selected"/>



</LinearLayout>

出现这种问题是我之前写的布局不规范,右边的textview设置成了铺满在5.0以前是不会不显示的,而在5.0的时候系统默认将右边的文字挤出布局所以5.0该布局就不显示左边的文字;修改之后的布局如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:orientation="vertical">



    <View

        android:layout_width="fill_parent"

        android:layout_height="1px"

        android:layout_marginTop="14dp"

        android:background="@color/abc_search_url_text_pressed"/>



    <RelativeLayout

        android:id="@+id/lay_coupons"

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:layout_marginBottom="14dp"

        android:visibility="visible">



        <TextView

            android:id="@+id/tv_coupons"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_alignParentRight="true"

            android:layout_margin="12dp"

            android:drawablePadding="10dp"

            android:drawableRight="@android:drawable/checkbox_off_background"

            android:gravity="right"

            android:text="1个"/>



        <TextView

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_marginBottom="12dp"

            android:layout_marginLeft="16dp"

            android:layout_marginRight="10dp"

            android:layout_marginTop="12dp"

            android:layout_alignParentLeft="true"

            android:layout_toLeftOf="@id/tv_coupons"

            android:text="我的收藏"

            android:textColor="@color/abc_search_url_text_holo"

            android:textSize="16sp"/>

    </RelativeLayout>



    <View

        android:layout_width="fill_parent"

        android:layout_height="1px"

        android:layout_below="@id/tv_coupons"

        android:background="@color/abc_search_url_text_selected"/>



</LinearLayout>

抱歉!评论已关闭.