1

我使用CardView顯示列表項目,其中每個列表項目包含兩個文本視圖,即 - 立即預訂/書本和詳細信息/細節。CardView中的圓角底部TextView

我想實現圓形底部的TextView,但在長方形

enter image description here

我要設計這樣的事情越來越:

enter image description here

這裏是我的XML:

<?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:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.v7.widget.CardView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:clickable="true" 
     android:focusable="true" 
     android:layout_margin="5dp" 
     app:cardCornerRadius="5dp" 
     app:cardElevation="2dp"> 

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

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

       ....... 

      <LinearLayout 
       android:layout_height="match_parent" 
       android:layout_width="match_parent" 
       android:orientation="horizontal" 
       android:layout_marginTop="5dp" 
       android:background="@color/more" 
       android:layout_weight="1"> 

       <TextView 
        android:id="@+id/btnBook" 
        android:layout_width="0dp" 
        android:layout_weight="1" 
        android:layout_height="wrap_content" 
        android:text="BOOK" 
        android:textColor="@android:color/background_light" 
        android:padding="5dp" 
        android:background="@null" 
        android:textAppearance="?android:textAppearanceMedium" 
        android:gravity="center" /> 

       <TextView 
        android:id="@+id/btnDetail" 
        android:layout_width="0dp" 
        android:layout_weight="1" 
        android:layout_height="wrap_content" 
        android:text="DETAILS" 
        android:background="@null" 
        android:textColor="@android:color/background_light" 
        android:padding="10dp" 
        android:textAppearance="?android:textAppearanceMedium" 
        android:gravity="center" /> 

      </LinearLayout> 

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

我必須改變才能完成它?

回答

1

集本backgrou第二含有textViews

<item>  
     <shape android:shape="rectangle"> 
      <solid android:color="@color/colorPrimary" /> 
      <corners android:bottomLeftRadius="cardview_corner_radius_value" 
       android:bottomRightRadius="cardview_corner_radius_value" /> 
     </shape> 
    </item> 

LinearLayoutTextView透明background

0
 1. make button.xml file and put it in drawable folder 
    <?xml version="1.0" encoding="utf-8"?> 
    <selector xmlns:android="http://schemas.android.com/apk/res/android" > 
    <item android:state_pressed="true" > 
     <shape android:shape="rectangle" > 
      <corners android:radius="3dip" /> 
      <stroke android:width="1dip" android:color="#5e7974" /> 
      <gradient android:angle="-90" android:startColor="#345953" android:endColor="#689a92" />    
     </shape> 
    </item> 
    <item android:state_focused="true"> 
     <shape android:shape="rectangle" > 
      <corners android:radius="3dip" /> 
      <stroke android:width="1dip" android:color="#5e7974" /> 
      <solid android:color="#58857e"/>  
     </shape> 
    </item> 
    <item > 
     <shape android:shape="rectangle" > 
      <corners android:radius="3dip" /> 
      <stroke android:width="1dip" android:color="#5e7974" /> 
      <gradient android:angle="-90" android:startColor="#8dbab3" android:endColor="#58857e" />    
     </shape> 
    </item> 
    </selector> 
2. then change your xml background of Linearlayout 
android:background="@color/more" 
to 
android:background="@drawable/button" 
+0

你可以把你自己的顏色代碼放在button.xml中 –

1

您必須在可繪製文件夾中爲此選擇器。

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > 
    <item> 
     <shape 
     android:shape="rectangle"> 
      <stroke android:width="2dp" android:color="@color/more" /> 
      <dotted android:color="#00FF0000" /> 
      <padding android:bottom="1dp"/> 
     </shape> 
    </item> 
</layer-list> 

然後爲背景設置背景。利用這一

android:background="@drawable/corner_selector" 

代替

android:background="@color/more" 
1

使文件rounded_border.xml在繪製文件夾

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" >   
<stroke 
     android:width="1dp" 
     android:color="@color/common_border_color" /> 

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

<padding 
     android:left="1dp" 
     android:right="1dp" 
     android:top="1dp" /> 

<corners android:radius="5dp" /> 
</shape> 

,並保持它的線性佈局的背景

<LinearLayout 
      android:layout_height="match_parent" 
      android:layout_width="match_parent" 
      android:orientation="horizontal" 
      android:layout_marginTop="5dp" 
      android:background="@drawable/rounded_border" 
      android:layout_weight="1"> 
0

這個最簡單的方法試着做這個佈局 here are the pic for example

<?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" 
    android:orientation="vertical" > 

<Button 
    android:id="@+id/btn" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/btnbackground" 
    android:layout_margin="20dp" 
    android:text="My Profile" 
    /> 

</LinearLayout> 

後,使在一個xml drawable文件夾btnbackground.xml

<?xml version="1.0" encoding="UTF-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 

<item android:drawable="@drawable/llabeforeclick3" 
    android:state_pressed="true"/> 
<item android:drawable="@drawable/llaafterclick3"/> 

</selector> 

然後再拍llabeforeclick3.xml在繪製目錄

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle" > 

    <solid android:color="#19384A" > 
    </solid> 

    <corners 
    android:bottomLeftRadius="10dp" 
    android:bottomRightRadius="10dp" 
    android:topRightRadius="10dp" 
    android:topLeftRadius="10dp" /> 

<stroke 
    android:width="0dp" 
    android:color="#19384A" /> 

<padding 
    android:left="4dp" 
    android:top="4dp" 
    android:right="4dp" 
    android:bottom="4dp" 
    android:color="#19384A" />  
</shape> 

後,使在繪製

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle" > 
    //background color 

    <solid android:color="#204A60" > 
    </solid> 

    <corners 
    android:bottomLeftRadius="10dp" 
    android:bottomRightRadius="10dp" 
    android:topRightRadius="10dp" 
    android:topLeftRadius="10dp" /> 
     //before clicked 

    <gradient 
    android:angle="45" 
    android:centerColor="#204A60" 
    android:centerX="20" 
    android:centerY="20" 
    android:endColor="#204A60" 
    android:gradientRadius="25" 
    android:startColor="#204A60" /> 

</shape> 

另一個XML llaafterclick3.xml如果有些哥們想使更多的圓角,然後用它來增加大小

 android:bottomLeftRadius="10dp" 
    android:bottomRightRadius="10dp" 
    android:topRightRadius="10dp" 
    android:topLeftRadius="10dp" 

這就解決了你的顏色代碼是dep結束於你,你需要把顏色代碼只有和radious。