2016-02-14 97 views
-3

我已經看到了很多應用程序中的這一點,但我不知道這究竟是什麼.... 任何人都可以告訴我嗎?其實,我想告訴我的應用程序一些文字與本次上調的背景之類的話.... 請告訴我如何得到這個效果..如何實現這種材質效果?

以下是圖像:

enter image description here

+0

@IntelliJ Amiya,我問的背景,而不是行 –

+3

它看起來像['CardView'](http://developer.android.com/training/material/lists-cards.html#CardView)有一個影子。這種效果當然可以在沒有'CardView'的情況下實現,但到目前爲止,使用它會更簡單。補充閱讀:['CardView'參考文檔](http://developer.android.com/reference/android/support/v7/widget/CardView.html)。具體來說,[cardElevation](http://developer.android.com/reference/android/support/v7/widget/CardView.html#attr_android.support.v7.cardview:cardElevation) –

+0

@NitishDash請參閱上面的評論。 –

回答

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


    <android.support.v7.widget.CardView 
     android:id="@+id/cardView" 
     android:layout_margin="20dp" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:orientation="vertical" 
      android:layout_height="wrap_content"> 
     <TextView 
      android:layout_width="match_parent" 
      android:text="My Title Text" 
      android:padding="20dp" 
      android:textSize="18sp" 
      android:textColor="#000" 
      android:layout_height="wrap_content" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="2dp" 
      android:background="#e6b121" 
      android:id="@+id/your_id" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:padding="20dp" 
       android:text="Lorem ipsum dolor sit amet, mel esse eripuit patrioque id. Id inimicus scripserit delicatissimi est, id vide velit erant sed. Has an veri mutat accumsan, te iusto dolore similique nec. An laboramus delicatissimi nam, ea brute consul vis." 
       android:id="@+id/textView17" /> 

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


</LinearLayout> 

,這將給你的結果是:

enter image description here

也試試這個:

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


    <android.support.v7.widget.CardView 
     android:id="@+id/cardView" 
     android:layout_margin="20dp" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:orientation="vertical" 
      android:layout_height="wrap_content"> 
     <TextView 
      android:layout_width="match_parent" 
      android:text="My Title Text" 
      android:padding="20dp" 
      android:textSize="18sp" 
      android:textColor="#000" 
      android:layout_height="wrap_content" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="2dp" 
      android:background="#e6b121" 
      android:id="@+id/your_id" /> 

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

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

        <TextView 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" 
         android:padding="10dp" 
         android:text="Screen On:" 
         android:id="@+id/textView17" /> 

        <TextView 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" 
         android:padding="10dp" 
         android:text="19m 28s" 
         android:id="@+id/textView18" /> 
       </LinearLayout> 

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

        <TextView 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" 
         android:padding="10dp" 
         android:text="Discharge while On/Off:" 
         android:id="@+id/textView19" /> 

        <TextView 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" 
         android:padding="10dp" 
         android:text="7%/3%" 
         android:id="@+id/textView20" /> 
       </LinearLayout> 
      </LinearLayout> 

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


</LinearLayout> 

enter image description here

但是,當然,你將需要實現一個自定義的適配器將其改編成ListViewRecyclerView

希望它能幫助! !