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

极客机器人

我正在尝试使用向右箭头和在其右侧具有2个textviews的垂直线来构建布局。

此布局将用于 RecyclerView

这是我正在使用的代码,

<?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但仍然没有用
历克斯

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

<?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>

上面示例的屏幕截图: 在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

前景在真实设备中不可见,但在模拟器中可见

USB设备在Vagrant中不可见

视图在约束布局中不可见

相对布局中不可见的视图

MySQL 数据在 Toad Edge 中可见,但在 CLI 中不可见

Href在scrapy结果中不可见,但在html中可见

Joomla模块在文章中可见,但在类别中不可见

为什么图像在Firefox中可见但在Chrome中不可见?

字符在vi中可见,但在cat中不可见。

文本选择在alert()中可见,但在html()中不可见

为什么Bootstrap轮播字幕在开发中可见但在生产中不可见?

使控件在 JavaScript 中可见,但在网页上不可见

为什么提交在 github 上可见,但在本地代表中不可见?

ImageView存在,但在显示中不可见

xcode 崩溃上传成功但在 crashlytics 中不可见

发布了android应用,但在Google Play中不可见

OnClick事件触发但在.aspx中不可见

StackPanel在物理设备上消失,但在Simulator中可见

内部树视图元素在 chrome 中不可见,在 IE11 中可见

远程USB设备在RDP中不可见

adb 设备在 Windows 子系统(WSL)中不可见

设备选项在android studio中不可见

表格中的不可见/可见提交按钮

如何在设计器中显示不可见的视图?

如何使一组视图在android中不可见

如何基于Android中的输入使视图不可见

MapQuickItem在模型/视图委托中不可见

在/在XML / XSL中可见

如何在TextInputLayout Android中更改setEndIconDrawable的可见性(可见,不可见或不可见)?