【发布时间】:2017-10-30 16:59:08
【问题描述】:
This is the layout image 我正在尝试在相对布局的图像上添加文本,三个垂直线。 带有 ID 的视图,Leftline 和 rightline 不可见,而带有 ID cardline 的视图可见。如何使所有视图可见?
<?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>
【问题讨论】:
-
你的
CardView有layout_height="wrap_content"和RelativeLayout有layout_height="match_parent".... 这显然没有意义... 为什么?您告诉父视图与直接子视图一样长,还告诉子视图与父视图一样长......这意味着无法计算高度 -
将相对布局更改为换行内容,视图仍然不可见
-
@Jani 可以在这里上传布局图片吗?
-
@LokeshDesai 添加了布局图片
-
@Jani 请检查我的回答..
标签: android xml android-relativelayout