2013-07-11 22 views
2

我在做一個應用程序與它的內部卡狀元意見的內容,但我有幾個問題:卡接口:無法適應內容和文本進行裁剪

  1. 我不能讓標籤線(藍線)遠離卡片文本。我已經嘗試了填充和邊距(從文本中的兩行圖像視圖和文本視圖),並沒有什麼似乎在這裏工作。

  2. 卡片標題的底部部分由於行距而被裁剪。我該如何解決這個問題並保持行距?

檢查這張截圖爲更好地理解:http://imgur.com/qsoCFrB

下面的代碼到卡上的背景和接口本身:

card_bg:

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item> 
     <shape android:shape="rectangle" 
      android:dither="true"> 

      <corners android:radius="1dp"/> 

      <solid android:color="#bdbdbd" /> 

     </shape> 
    </item> 

    <item android:bottom="2dp"> 
     <shape android:shape="rectangle" 
      android:dither="true"> 

      <corners android:radius="2dp" /> 

      <solid android:color="@android:color/white" /> 

      <padding android:bottom="6dp" 
       android:left="6dp" 
       android:right="6dp" 
       android:top="4dp" /> 
     </shape> 
    </item> 
</layer-list> 

主要胡亞蓉:

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="4dp" 
     android:layout_marginLeft="6dp" 
     android:layout_marginRight="6dp" 
     android:layout_marginTop="4dp" 
     android:background="@drawable/card_bg" > 

     <ImageView 
      android:id="@+id/iconView0001" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:paddingTop="6dp" 
      android:src="@drawable/icon_example" /> 

    <ImageView 
      android:id="@+id/labelSource0001" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignBottom="@+id/cardText0001" 
      android:layout_marginTop="4dp" 
      android:background="@drawable/card_label" /> 

     <TextView 
      android:id="@+id/cardTitle0001" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignTop="@+id/cardText0001" 
      android:layout_toRightOf="@+id/iconView0001" 
      android:fontFamily="sans-serif-condensed" 
      android:maxLines="2" 
      android:paddingLeft="4dp" 
      android:lineSpacingExtra="-6dp"   
      android:text="@string/card_title_002" 
      android:textColor="#717171" 
      android:textSize="16sp" /> 

     <TextView 
      android:id="@+id/cardText0001" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/iconView0001" 
      android:fontFamily="sans-serif" 
      android:layout_marginTop="4dp" 
      android:maxLines="1" 
      android:text="@string/card_desc_002" 
      android:textColor="#acacac" 
      android:textSize="12sp" /> 

    </RelativeLayout> 

</FrameLayout> 

提前致謝。

回答

1

這是GitHub上Gist的創建者!

您是否嘗試過增加RelativeLayout上的填充,也許可以解決該問題?甚至在TextView元素上?

試着這樣做,看看結果是什麼。

編輯:另外,爲什麼在文本視圖內有負行距?

DOUBLE編輯:所以發生了什麼事是你layout_alignBottom在linkTitle的TextView比的兩行文本的高度變短,因此它被裁剪的標題TextView的高度限制,該圖標的ImageView的。刪除此屬性可解決問題。

類似的問題是標籤的形狀,alignBottom是什麼搞砸了。

將layout_alignBottom更改爲layout_below,然後使用填充/邊距應該會影響您的位置。

這裏是你的代碼的更新版本應該解決您的問題:

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/linkCardView" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="#ccc" > 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="4dp" 
     android:layout_marginLeft="6dp" 
     android:layout_marginRight="6dp" 
     android:layout_marginTop="4dp" 
     android:background="@drawable/card_bg"> 

     <TextView 
      android:id="@+id/linkTitle" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_toRightOf="@+id/faviconView0001" 
      android:padding="4dp" 
      android:maxLines="2" 
      android:text="@string/link_title_001" 
      android:textColor="#717171" 
      android:textSize="17sp" /> 

     <TextView 
      android:id="@+id/linkDesc0001" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/linkTitle" 
      android:paddingTop="6dp" 
      android:paddingBottom="9dp" 
      android:fontFamily="sans-serif" 
      android:maxLines="1" 
      android:text="@string/link_desc_001" 
      android:textColor="#acacac" 
      android:textSize="13sp" /> 

     <ImageView 
      android:id="@+id/faviconView0001" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:paddingTop="6dp" 
      android:layout_alignParentLeft="true" 
      android:src="@drawable/favicon_example" /> 

     <View 
      android:layout_height="0dp" 
      android:layout_width="fill_parent" 
      /> 
     <ImageView 
      android:id="@+id/labelSource0001" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/linkDesc0001" 
      android:background="@drawable/card_label" /> 
    </RelativeLayout> 
</FrameLayout> 

我希望這一切幫助!

+0

它沒有在TextView padding上工作=/ RelativeLayout只有邊距,增加這些邊距或添加邊距? 關於負值,文本中的線條會更接近,因此我可以在卡片中放入更多文本 – guilhermexot

+1

我已經使用解決方案編輯了我的答案,在查看代碼後我發現了它。我希望這是您尋找的解決方案! – iheanyi