2016-09-28 41 views

回答

0

drawable文件夾中創建rounde_corner.xml並粘貼以下成

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="@color/white"/> 
    <corners android:radius="4dp"/> 
</shape> 

並應用爲background到您的佈局

+0

謝謝。這看起來很好。 –

+0

'我的聲望小於15,所以我不能投票你的答案' –

+0

好吧,我會做,但4分鐘後,因爲它提醒了錯誤IDK爲什麼? –

0

嘗試使用cardview。然後將cardCornerRadius設置爲圓角,對於陰影設置cardElevation

Check out this link for further documentation.

例如:

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/material_blue_500" 
     android:paddingBottom="1dp"> 

     <android.support.v7.widget.CardView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="@dimen/stock_detail_margin" 
      android:layout_marginEnd="@dimen/heading_item_extra_padding" 
      android:layout_marginLeft="@dimen/heading_item_extra_padding" 
      android:layout_marginRight="@dimen/heading_item_extra_padding" 
      android:layout_marginStart="@dimen/heading_item_extra_padding" 
      android:layout_marginTop="@dimen/stock_detail_margin" 
      app:cardCornerRadius="5dp" 
      app:cardElevation="15dp"> 


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

       <LinearLayout 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:layout_weight="3" 
        android:gravity="center" 
        android:orientation="vertical"> 


        <TextView 
         android:id="@+id/txt_symbol" 
         style="@style/StockSymbolTextStyle" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_marginTop="5dp" 
         android:gravity="center" 
         android:hint="YHOO" /> 


        <TextView 
         android:id="@+id/txt_company" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_marginTop="5dp" 
         android:gravity="center" 
         android:hint="Yahoo Incorporated Inc." 
         android:textAppearance="?android:attr/textAppearanceSmall" /> 

       </LinearLayout> 

       <android.support.v7.widget.CardView 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_margin="5dp" 
        android:layout_weight="1" 
        app:cardBackgroundColor="@android:color/holo_orange_dark" 
        app:cardCornerRadius="5dp"> 

        <LinearLayout 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_gravity="center" 
         android:gravity="center" 
         android:orientation="vertical"> 


         <TextView 
          android:id="@+id/txt_price" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_marginTop="5dp" 
          android:gravity="center" 
          android:text="57.90" 
          android:textAppearance="?android:attr/textAppearanceLarge" 
          android:textColor="@android:color/white" /> 

         <TextView 
          android:id="@+id/txt_percent" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_marginTop="5dp" 
          android:gravity="center" 
          android:text="-98.2%" 
          android:textAppearance="?android:attr/textAppearanceSmall" 
          android:textColor="@android:color/white" /> 

         <TextView 
          android:id="@+id/txt_change_amt" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_marginTop="5dp" 
          android:gravity="center" 
          android:text="-2.44" 
          android:textAppearance="?android:attr/textAppearanceSmall" 
          android:textColor="@android:color/white" /> 
        </LinearLayout> 
       </android.support.v7.widget.CardView> 


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

    </LinearLayout> 

這段代碼產生這樣的佈局:

enter image description here