2017-10-21 111 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中寫入此代碼,它將起作用 –

相關問題