这是Android Studio中的预览。一切都好。左侧的红色条显示。但它在设备上是不可见的。经过6个小时的疼痛,我正在寻求帮助。它是活动中片段的列表视图中的一行。
更新:如果我将layout_height设置为常量,例如50dp它变得可见。否则视图的高度为0.如何将高度与父级匹配?
这是布局xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants"
android:background="@android:color/white"
>
<View
android:id="@+id/owner_indicator"
android:layout_width="30dp"
android:layout_height="match_parent"
android:background="@color/light_red">
</View>
<TextView
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/message"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/owner_indicator"
android:layout_toLeftOf="@+id/upvote_button"
android:layout_toStartOf="@+id/upvote_button"
android:paddingBottom="33dp"
/>
<ImageView
android:layout_marginLeft="4dp"
android:tint="@color/main_color"
android:contentDescription="@string/action_time_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/camera_image"
android:src="@drawable/ic_action_photo"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@+id/owner_indicator"
/>
<ImageView
android:layout_marginLeft="4dp"
android:tint="@color/main_color"
android:contentDescription="@string/action_time_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:src="@drawable/ic_action_time"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@+id/camera_image"
/>
<TextView
android:textColor="@color/main_color"
android:paddingBottom="6dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/time_label"
android:layout_alignParentBottom="true"
android:layout_alignBottom="@+id/imageView"
android:layout_toRightOf="@+id/imageView"
android:layout_toEndOf="@+id/imageView" />
<ImageButton
android:contentDescription="@string/upvote"
android:minWidth="50dp"
android:minHeight="50dp"
android:background="?attr/selectableItemBackground"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/vote_button_states"
android:id="@+id/upvote_button"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:onClick="upvoteTouched"/>
<TextView
android:textColor="@color/main_color"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:minWidth="50dp"
android:gravity="center"
android:id="@+id/rating_label"
android:layout_below="@+id/upvote_button"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<ImageButton
android:contentDescription="@string/downvote"
android:minWidth="50dp"
android:minHeight="50dp"
android:background="?attr/selectableItemBackground"
android:src="@drawable/vote_button_states"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/downvote_button"
android:layout_below="@+id/rating_label"
android:layout_alignLeft="@+id/upvote_button"
android:layout_alignStart="@+id/upvote_button"
android:onClick="downvoteTouched"/>
<TextView
android:textColor="@color/light_gray"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/comments_label"
android:layout_alignParentBottom="true"
android:layout_alignTop="@+id/time_label"
android:layout_toRightOf="@+id/time_label"
android:layout_toEndOf="@+id/time_label"
android:layout_toLeftOf="@+id/downvote_button"
android:layout_toStartOf="@+id/downvote_button"
android:paddingBottom="7dp"
android:layout_marginLeft="37dp"
android:layout_marginStart="37dp" />
</RelativeLayout>