布局.xml有时在某些Android版本上无效

时间:2017-08-31 00:28:36

标签: java android xml layout relativelayout

我一直在尝试制作布局。但是在某些Android版本上,比如api 25。

你能看出我做错了什么吗? BTW由于某些原因我的代码不适合这里。 Android工作室不会给我一个错误代码或其他东西。它使我的.apk很好。所有页面都在工作,但这不是。

'<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:padding="@dimen/space16">
            <ImageView
                android:id="@+id/iv_user"
                android:layout_width="45dp"
                android:layout_height="45dp"
                android:background="@drawable/head"/>
            <RatingBar
                android:id="@+id/ratingBar"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_marginLeft="@dimen/space16"
                android:layout_marginBottom="@dimen/space8"
                android:rating="3"
                android:numStars="5"
                android:isIndicator="true"
                style="@style/RatingBar"
                android:layout_toRightOf="@id/iv_user"/>
            <TextView
                android:id="@+id/tv_username"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/ratingBar"
                android:layout_alignLeft="@id/ratingBar"
                android:text="Henrie, €12.- p/u"
                android:textColor="@color/colorTextDark"
                android:textSize="@dimen/h3"
                android:textAppearance="@style/SemiBold"/>
            <TextView
                android:id="@+id/tv_date"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/ratingBar"
                android:layout_marginLeft="@dimen/space8"
                android:layout_toRightOf="@id/tv_username"
                android:layout_alignBaseline="@id/tv_username"
                android:text="Oudijzer handel"

                android:textColor="@color/colorTextGrey"
                android:textSize="12sp"
                android:textAppearance="@style/Regular"/>
            <TextView
                android:id="@+id/tv_text_comment"
                android:layout_width="wrap_content"
                android:layout_marginTop="@dimen/space8"
                android:layout_height="wrap_content"
                android:layout_below="@id/tv_username"
                android:layout_alignLeft="@id/ratingBar"
                style="@style/Text14Reg"/>
        </RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="15dp"
    android:paddingTop="96dp">
    <ImageView
        android:id="@+id/iv_user1"
        android:layout_width="45dp"
        android:layout_height="45dp"
        android:background="@drawable/head2"/>
    <RatingBar
        android:id="@+id/ratingBar1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginLeft="@dimen/space16"
        android:layout_marginBottom="@dimen/space8"
        android:rating="4.5"
        android:numStars="5"
        android:isIndicator="true"
        style="@style/RatingBar"
        android:layout_toRightOf="@id/iv_user1"/>
    <TextView
        android:id="@+id/tv_username1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/ratingBar1"
        android:layout_alignLeft="@id/ratingBar1"
        android:text="Hetty, €5.- p/u"
        android:textColor="@color/colorTextDark"
        android:textSize="@dimen/h3"
        android:textAppearance="@style/SemiBold"/>
    <TextView
        android:id="@+id/tv_date1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/ratingBar1"
        android:layout_marginLeft="@dimen/space8"
        android:layout_toRightOf="@id/tv_username1"
        android:layout_alignBaseline="@id/tv_username1"
        android:text="Haken met wol en andere stof"
        android:textColor="@color/colorTextGrey"
        android:textSize="12sp"
        android:textAppearance="@style/Regular"/>
    <TextView
        android:id="@+id/tv_text_comment1"
        android:layout_width="wrap_content"
        android:layout_marginTop="@dimen/space8"
        android:layout_height="wrap_content"
        android:layout_below="@id/tv_username1"
        android:layout_alignLeft="@id/ratingBar1"
        style="@style/Text14Reg"/>
</RelativeLayout>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="15dp"
    android:paddingTop="176dp">
    <ImageView
        android:id="@+id/iv_user2"
        android:layout_width="45dp"
        android:layout_height="45dp"
        android:background="@drawable/head3"/>
    <RatingBar
        android:id="@+id/ratingBar2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginLeft="@dimen/space16"
        android:layout_marginBottom="@dimen/space8"
        android:rating="4.5"
        android:numStars="5"
        android:isIndicator="true"
        style="@style/RatingBar"
        android:layout_toRightOf="@id/iv_user2"/>
    <TextView
        android:id="@+id/tv_username2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/ratingBar2"
        android:layout_alignLeft="@id/ratingBar2"
        android:text="Peter, €106.- p/u"
        android:textColor="@color/colorTextDark"
        android:textSize="@dimen/h3"
        android:textAppearance="@style/SemiBold"/>
    <TextView
        android:id="@+id/tv_date2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/ratingBar2"
        android:layout_marginLeft="@dimen/space8"
        android:layout_toRightOf="@id/tv_username2"
        android:layout_alignBaseline="@id/tv_username2"
        android:text="Professioneel APK keurder"
        android:textColor="@color/colorTextGrey"
        android:textSize="12sp"
        android:textAppearance="@style/Regular"/>
    <TextView
        android:id="@+id/tv_text_comment2"
        android:layout_width="wrap_content"
        android:layout_marginTop="@dimen/space8"
        android:layout_height="wrap_content"
        android:layout_below="@id/tv_username2"
        android:layout_alignLeft="@id/ratingBar2"
        style="@style/Text14Reg"/>
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="15dp"
    android:paddingTop="262dp">
    <ImageView
        android:id="@+id/iv_user3"
        android:layout_width="45dp"
        android:layout_height="45dp"
        android:background="@drawable/head4"/>
    <RatingBar
        android:id="@+id/ratingBar3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginLeft="@dimen/space16"
        android:layout_marginBottom="@dimen/space8"
        android:rating="5"
        android:numStars="5"
        android:isIndicator="true"
        style="@style/RatingBar"
        android:layout_toRightOf="@id/iv_user3"/>
    <TextView
        android:id="@+id/tv_username3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/ratingBar3"
        android:layout_alignLeft="@id/ratingBar3"
        android:text="Kim, Vanaf €1.-"
        android:textColor="@color/colorTextDark"
        android:textSize="@dimen/h3"
        android:textAppearance="@style/SemiBold"/>
    <TextView
        android:id="@+id/tv_date3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/ratingBar3"
        android:layout_marginLeft="@dimen/space8"
        android:layout_toRightOf="@id/tv_username3"
        android:layout_alignBaseline="@id/tv_username3"
        android:text="Ik maak en verkoop kettingen"
        android:textColor="@color/colorTextGrey"
        android:textSize="12sp"
        android:textAppearance="@style/Regular"/>
    <TextView
        android:id="@+id/tv_text_comment3"
        android:layout_width="wrap_content"
        android:layout_marginTop="@dimen/space8"
        android:layout_height="wrap_content"
        android:layout_below="@id/tv_username3"
        android:layout_alignLeft="@id/ratingBar3"
        style="@style/Text14Reg"/>
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="15dp"
    android:paddingTop="358dp">
    <ImageView
        android:id="@+id/iv_user4"
        android:layout_width="45dp"
        android:layout_height="45dp"
        android:background="@drawable/head5"/>
    <RatingBar
        android:id="@+id/ratingBar4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginLeft="@dimen/space16"
        android:layout_marginBottom="@dimen/space8"
        android:rating="4"
        android:numStars="5"
        android:isIndicator="true"
        style="@style/RatingBar"
        android:layout_toRightOf="@id/iv_user4"/>
    <TextView
        android:id="@+id/tv_username4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/ratingBar4"
        android:layout_alignLeft="@id/ratingBar4"
        android:text="Manon, n.o.t.k"
        android:textColor="@color/colorTextDark"
        android:textSize="@dimen/h3"
        android:textAppearance="@style/SemiBold"/>
    <TextView
        android:id="@+id/tv_date4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/ratingBar4"
        android:layout_marginLeft="@dimen/space8"
        android:layout_toRightOf="@id/tv_username4"
        android:layout_alignBaseline="@id/tv_username4"
        android:text="Kledingontwerpster"
        android:textColor="@color/colorTextGrey"
        android:textSize="12sp"
        android:textAppearance="@style/Regular"/>
    <TextView
        android:id="@+id/tv_text_comment4"
        android:layout_width="wrap_content"
        android:layout_marginTop="@dimen/space8"
        android:layout_height="wrap_content"
        android:layout_below="@id/tv_username4"
        android:layout_alignLeft="@id/ratingBar4"
        style="@style/Text14Reg"/>
</RelativeLayout>

Picture of how it needs to look like. On some way, its not working

1 个答案:

答案 0 :(得分:1)

RecyclerView确实是实现此布局的最佳解决方案。你不应该在布局中使用那么多的RelativeLayouts(你实际上没有父布局,所以可能是你遇到麻烦的原因)。