2016-06-15 83 views
0

[問題解決]我不知道爲什麼高度:wrap_content不能正常工作,我只是改變它匹配父。無論如何,問題解決了。不想再花更多時間在這個奇怪的事情上。android LinearLayout顯示問題

我正在使用LinearLayout構造CardView。但是,我有這種奇怪的情況。 Jinesh Francis的代碼完美地工作,但是當我將配置複製並粘貼到我的代碼中時,問題保持不變。

Normal Title

Long Long Title

爲什麼不能長標題完全顯示?

佈局如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content"> 

<android.support.v7.widget.CardView 
    android:id="@+id/movieCardView" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="5dp" 
    android:layout_marginBottom="5dp" 
    android:layout_gravity="center" 
    android:background="@color/bacgroundCardView"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <ImageView 
      android:id="@+id/movieImage" 
      android:layout_width="70dp" 
      android:layout_height="90dp" 
      android:layout_marginBottom="4dp" 
      android:layout_marginLeft="4dp" 
      android:layout_marginRight="4dp" 
      android:layout_marginTop="4dp" 
      android:scaleType="fitXY" 
      android:src="@drawable/selfie" /> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:orientation="vertical" 
      android:layout_height="wrap_content"> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_weight="1" 
       android:layout_height="0dp"> 

       <TextView 
        android:id="@+id/movieTitle" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_weight="8" 
        android:textSize="15dp" 
        android:textColor="#000" 
        android:textStyle="bold" 
        android:text="Long long long long long long long long Title"/> 

       <TextView 
        android:id="@+id/movieRating" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_weight="0.7" 
        android:textSize="12dp" 
        android:textStyle="bold" 
        android:text="7.0" /> 

       <CheckBox 
        android:id="@+id/checkBox" 
        android:layout_width="0dp" 
        android:layout_weight="1" 
        android:layout_height="wrap_content" 
        android:scaleX="0.70" 
        android:scaleY="0.70" /> 

      </LinearLayout> 

      <TextView 
       android:id="@+id/movieDescription" 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_weight="1" 
       android:textSize="10dp" 
       android:text="So many many many many many many many many many many many many description" /> 

     </LinearLayout> 

    </LinearLayout> 

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

感謝您的任何建議

+0

這是不夠的,只寫XML標記。編輯您的帖子幷包含屬性。 – Karakuri

+0

發佈您的完整佈局文件 –

+0

您在relativeLayout中使用LinearLayout,並設置標題的權重..這就是爲什麼它給這個輸出 – NehaK

回答

0

與像權重線性佈局嘗試這

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <ImageView 
     android:layout_width="80dp" 
     android:layout_height="100dp" 
     android:src="@drawable/demo2"/> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:orientation="vertical" 
     android:layout_height="wrap_content"> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_weight="1" 
      android:layout_height="0dp"> 
      <TextView 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:textSize="20sp" 
       android:layout_weight="1" 
       android:textColor="#000" 
       android:textStyle="bold" 
       android:text="Long Long Long Long Long Tittle"/> 
      <TextView 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="0.25" 
       android:text="7.0"/> 
      <CheckBox 
       android:layout_width="0dp" 
       android:layout_weight=".25" 
       android:layout_height="wrap_content" /> 
     </LinearLayout> 
     <TextView 
      android:layout_width="match_parent" 
      android:text="so many many many many many many many many many many many many many many many many description" 
      android:layout_height="0dp" 
      android:layout_weight="1"/> 
    </LinearLayout> 
</LinearLayout> 

我得到這個輸出

Output

+0

感謝您的幫助Jinesh。有趣的是,你的代碼完美運行,但是當我從你的代碼中一行一行地拷貝和粘貼配置到我的代碼時,問題保持不變,我覺得自己被Android Studio愚弄了, – Rangtian

2

集RelativeLayout的物業調整佈局

Relative Layout Property are below 
alignparentLeft,alignLeft 
alignparentRight,alignRight 
alignparentBottom,alignBottom 
alignparentTop,alignTop 
+0

感謝您的幫助Divyesh,似乎那些屬性不是關鍵。 – Rangtian