2017-10-21 114 views
0

我正在尝试使用右箭头和垂直线以及其右侧的2个文本视图构建布局。在设备中查看不可见,但在XML中可见

此布局将在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> 

这是上述布局的结果

enter image description here

的当我在我的设备上运行输出时,蓝色线条不可见,但如图所示以XML显示

我的问题

  1. 我如何让它在我的设备可见?
  2. 蓝线是非常大的我试过wrap_content但仍然没有工作
+0

我尝试这样做的代码和蓝线是在两个编辑器和实际的装置可见。你在用哪种设备? –

+0

@NovoLucas设备是红米Note 3 –

+0

奇怪的是,即使我使用红米,它是可见的。虽然解决问题的好处很多。 –

回答

0

适合线你可以简单地调整你的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> 

截图上面的例子中的: enter image description here

+0

'lineView'不可见 –

+0

设备是redmi注意3 –

+0

我很害怕,我的糟糕,只需替换'android:layout_alignParentStart =“true”在lineview中''android:layout_alignParentTop =“true”'。我也会更新我的答案。 –

0

要根据内容使用本

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

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

        /> 
<LinearLayout /> 
+0

想要在'RelativeLayout'中 –

+0

是在RelativeLayout中写入此代码,它将起作用 –

相关问题