首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >视图在设备中不可见,但在XML中可见。

视图在设备中不可见,但在XML中可见。
EN

Stack Overflow用户
提问于 2017-10-21 05:13:04
回答 2查看 1.9K关注 0票数 1

我试图建立一个布局与一个右箭头和一个垂直线与2个文本视图的权利。

此布局将在RecyclerView中使用

这是我正在使用的代码,

代码语言:javascript
运行
复制
<?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"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/white"
    android:clickable="true"
    android:id="@+id/rootLayout"

    >
    <android.support.v7.widget.CardView
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white"            
        android:layout_margin="@dimen/app_margin"
        card_view:cardCornerRadius="4dp"
        card_view:cardElevation="4dp"
        >

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

            <View
                android:layout_width="20dp"
                android:layout_height="match_parent"
                android:layout_alignParentStart="true"
                android:id="@+id/lineView"
                android:layout_marginLeft="15dp"
                android:background="@color/colorPrimary"
                />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/name"
                android:layout_toRightOf="@+id/lineView"


                />
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/type"
                android:layout_toRightOf="@+id/lineView"
                android:layout_below="@+id/name"

                />


            <android.support.v7.widget.AppCompatImageView
                android:layout_width="50dp"
                android:layout_height="50dp"
                app:srcCompat="@drawable/right_arrow"
                android:layout_alignParentEnd="true"
                android:layout_centerInParent="true"

                android:id="@+id/right_arrow"
                />

        </RelativeLayout>

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


</LinearLayout>

这是上述布局的结果。

当我在设备上运行输出时,蓝线是不可见的,但在XML中是可见的,如下所示

我的问题

  1. 如何使它在我的设备中可见?
  2. 蓝线很大,我试过wrap_content,但还是没有用
EN

Stack Overflow用户

回答已采纳

发布于 2017-10-21 05:28:29

您可以简单地将lineView对齐到文本视图的高度。否则它会长到设备的高度。参考这个样本。

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView 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="wrap_content"
    android:layout_margin="10dp"
    app:cardBackgroundColor="#FFFFFF"
    app:contentPadding="10dp">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical">

        <View
            android:id="@+id/view"
            android:layout_width="20dp"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/linearLayout"
            android:layout_alignParentTop="true"
            android:background="@color/colorPrimary" />

        <LinearLayout
            android:id="@+id/linearLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_toEndOf="@+id/view"
            android:orientation="vertical"
            android:padding="10dp">

            <TextView
                android:id="@+id/name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="ABCD"
                android:textSize="15sp" />

            <TextView
                android:id="@+id/value"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="ABCD"
                android:textSize="15sp" />
        </LinearLayout>

        <ImageView
            android:id="@+id/img"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_alignParentEnd="true"
            android:layout_centerVertical="true"
            app:srcCompat="@drawable/ic_keyboard_arrow_right_black_24px" />
    </RelativeLayout>
</android.support.v7.widget.CardView>

上述示例的屏幕截图:

票数 3
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46860275

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档