Android 视图在Relativelayout中不可见

Android 视图在Relativelayout中不可见,android,xml,android-relativelayout,Android,Xml,Android Relativelayout,我试图添加文本,在相对布局的图像上添加三条垂直线。 ID为的视图、Leftline和rightline不可见,而ID为cardline的as视图可见。如何使所有视图可见 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.androi

我试图添加文本,在相对布局的图像上添加三条垂直线。 ID为的视图、Leftline和rightline不可见,而ID为cardline的as视图可见。如何使所有视图可见

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

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginBottom="6dp">
        <!--app:cardBackgroundColor="#000000"-->


        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp">




            <ImageView
                android:layout_marginBottom="40dp"
                android:id="@+id/main_image_story"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:contentDescription="@string/contentdescimage"
                android:src="@drawable/vijaymallya"
                android:scaleType="fitXY"
                android:adjustViewBounds="true"/>

            <View
                android:id="@+id/leftline"
                android:layout_width="4dp"
                android:layout_height="match_parent"
                android:background="#f49a32"/>


            <View
                android:id="@+id/rightline"
                android:layout_width="4dp"
                android:layout_height="match_parent"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:background="#f49a32"/>




            <View
                android:id="@+id/cardline"
                android:layout_width="match_parent"
                android:layout_height="6dp"
                android:background="#f49a32" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/cardline"
                android:background="@drawable/background_gradient"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/date_story"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="3dp"
                    android:layout_marginLeft="10dp"
                    android:layout_marginStart="10dp"
                    android:layout_marginTop="8dp"
                    android:shadowColor="#000000"
                    android:shadowRadius="2"
                    android:textColor="#ffffff"
                    android:textSize="10sp"
                    tools:text="9.30 PM, 28 APRIL 2017" />



            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:background="@drawable/background_gradient2"
                android:orientation="vertical">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="15dp"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="15dp"
                    android:layout_marginStart="10dp">

                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="match_parent">

                        <View
                            android:layout_width="5dp"
                            android:layout_height="wrap_content"
                            android:layout_marginEnd="11dp"
                            android:layout_marginRight="11dp"
                            android:background="#ffffff"/>

                    </LinearLayout>


                    <TextView
                        android:id="@+id/substory_title_story"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:lineSpacingExtra="0sp"
                        android:shadowColor="#000000"
                        android:shadowRadius="2"
                        android:textColor="#ffffff"
                        android:textSize="16sp"
                        tools:text="Vijay Mallya Misled Us On Wealth, Says Supreme Court, Hauls Him For Contempt" />

                </LinearLayout>

                <LinearLayout
                    android:id="@+id/tags"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="9dp"
                    android:layout_marginRight="9dp"
                    android:layout_marginTop="10dp"
                    android:orientation="horizontal">

                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="6" />

                    <TextView
                        android:id="@+id/number_of_articles_story"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="4"
                        android:gravity="end"
                        android:shadowColor="#000000"
                        android:shadowRadius="2"
                        android:textColor="#f49a32"
                        android:textSize="11sp"
                        tools:text="7 ARTICLES - EXPLORE" />

                </LinearLayout>
            </LinearLayout>

        </RelativeLayout>


     </android.support.v7.widget.CardView>

    </LinearLayout>

根据您的布局使用填充和边距

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="5dp"
    android:layout_margin="5dp"
    android:orientation="vertical">
  .....
</LinearLayout>

.....

请尝试此更改。我已在演示应用程序中尝试,它正在工作

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

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:layout_marginBottom="6dp">


        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp">

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="horizontal">


                <ImageView
                    android:id="@+id/main_image_story"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_gravity="center"
                    android:layout_marginBottom="40dp"
                    android:adjustViewBounds="true"
                    android:scaleType="fitXY"
                    android:src="@drawable/dubai" />

                <View
                    android:id="@+id/leftline"
                    android:layout_width="4dp"
                    android:layout_height="match_parent"
                    android:layout_gravity="start"
                    android:background="#f49a32" />

                <View
                    android:id="@+id/rightline"
                    android:layout_width="4dp"
                    android:layout_height="match_parent"
                    android:layout_gravity="end"
                    android:background="#f49a32" />
            </FrameLayout>


            <View
                android:id="@+id/cardline"
                android:layout_width="match_parent"
                android:layout_height="6dp"
                android:background="#f49a32" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/cardline"
                android:background="@color/white"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/date_story"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="3dp"
                    android:layout_marginLeft="10dp"
                    android:layout_marginStart="10dp"
                    android:layout_marginTop="8dp"
                    android:shadowColor="#000000"
                    android:shadowRadius="2"
                    android:textColor="#ffffff"
                    android:textSize="10sp"
                    tools:text="9.30 PM, 28 APRIL 2017" />


            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:background="@color/white"
                android:orientation="vertical">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="15dp"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="15dp"
                    android:layout_marginStart="10dp">

                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="match_parent">

                        <View
                            android:layout_width="5dp"
                            android:layout_height="wrap_content"
                            android:layout_marginEnd="11dp"
                            android:layout_marginRight="11dp"
                            android:background="#ffffff" />

                    </LinearLayout>


                    <TextView
                        android:id="@+id/substory_title_story"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:lineSpacingExtra="0sp"
                        android:shadowColor="#000000"
                        android:shadowRadius="2"
                        android:textColor="#ffffff"
                        android:textSize="16sp"
                        tools:text="Vijay Mallya Misled Us On Wealth, Says Supreme Court, Hauls Him For Contempt" />

                </LinearLayout>

                <LinearLayout
                    android:id="@+id/tags"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="9dp"
                    android:layout_marginRight="9dp"
                    android:layout_marginTop="10dp"
                    android:orientation="horizontal">

                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="6" />

                    <TextView
                        android:id="@+id/number_of_articles_story"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="4"
                        android:gravity="end"
                        android:shadowColor="#000000"
                        android:shadowRadius="2"
                        android:textColor="#f49a32"
                        android:textSize="11sp"
                        tools:text="7 ARTICLES - EXPLORE" />

                </LinearLayout>
            </LinearLayout>

        </RelativeLayout>


    </android.support.v7.widget.CardView>

</LinearLayout>


希望这能帮助你…如果没有,请告诉我…会找到其他方法…

你的
cardwiew
layout\u height=“wrap\u content”
RelativeLayout
layout\u height=“match\u parent”
。。。。这显然没有道理。。。为什么?您告诉父视图和直接子视图一样长,还告诉子视图和它的父视图一样长。。。这意味着不能计算高度将相对布局更改为包裹内容,视图仍然不能visible@Jani你能在这里上传版面图片吗?@LokeshDesai添加了版面image@Jani请检查我的答案。谢谢,它有效。但是你能告诉我我以前的代码有什么问题吗?@Jani首先你有属性匹配的图像视图\U parent…scale type=fitxy和adjustviewbound=true…这就是为什么你的相对性允许图像覆盖左右两个视图的原因…没有其他…否则你的代码在你提供的框架布局中也很好,我将scale type=fitxy和adjustviewbound=true设置为不收缩图像(否则图像将收缩),在这种情况下视图可见。我必须使adjustviewbound=true,否则我的图像会缩小。为什么它只发生在相对布局上?没有你的代码是好的…每个布局都有自己的行为framelayout将显示布局层,因此对于你的要求,使用它是完美的。。。。