带有分隔线的 Cardview
Cardview with dividers in it
我见过那些 CardViews
(我不确定它们甚至 CardViews
)在很多应用程序中都使用分隔线,所以我猜有一个简单的方法创建它们。
我想问一下具体是怎么做到的?那些甚至 CardViews
?
我无法找到更多关于它们的信息,因为我不知道 View
的确切名称,所以如果有人可以指导我使用代码示例,我将不胜感激。
图片示例:
您可以使用此代码,这可能会有所帮助
<android.support.v7.widget.CardView
android:id="@+id/cardview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_large"
android:layout_marginRight="@dimen/margin_large"
android:elevation="100dp"
card_view:cardBackgroundColor="@android:color/white"
card_view:cardCornerRadius="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center_vertical"
android:paddingLeft="25dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Conversations" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@android:color/darker_gray" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="30dp"
android:paddingTop="20dp"
android:paddingBottom="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="game" />
...
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
显示的屏幕截图显示了一个普通的 CardView,其中的视图作为分隔符。
如果您搜索类似的东西,则没有 DividerView 或类似的东西。只需使用带有高度和背景的简单 View
。
我的图书馆里有类似的东西。我用它来创建分隔线:
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/stroke"/>
card_library.xml
<?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:paddingBottom="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="@+id/libraryname"
style="@style/CardTitle"
android:fontFamily="sans-serif-condensed"
android:textStyle="normal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"/>
<TextView
android:id="@+id/libraryversion"
style="@style/CardTitle"
android:fontFamily="sans-serif-condensed"
android:textStyle="normal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_marginTop="4dp"
android:gravity="left|bottom"
android:maxLines="1"
android:textSize="12sp"/>
<TextView
android:id="@+id/librarycreator"
style="@style/CardTitle"
android:fontFamily="sans-serif-condensed"
android:textStyle="normal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:gravity="right"
android:maxLines="2"
android:textSize="14sp"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="4dp"
android:background="@color/stroke"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:padding="4dp">
<TextView
android:id="@+id/description"
style="@style/CardText"
android:fontFamily="sans-serif-condensed"
android:textStyle="normal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:maxLines="20">
</TextView>
</LinearLayout>
</LinearLayout>
它将看起来像这样:
设置 app:cardElevation="0dp" 然后使用视图 - 见下文
<android.support.v7.widget.CardView
android:id="@+id/cv"
xmlns:android="http://schemas.android.com/apk/res/android"
app:cardElevation="0dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">
<!-- Insert UI elements -->
<View
android:layout_width="fill_parent"
android:background="@android:color/darker_gray"
android:layout_height="2dp"/>
</android.support.v7.widget.CardView>
我见过那些 CardViews
(我不确定它们甚至 CardViews
)在很多应用程序中都使用分隔线,所以我猜有一个简单的方法创建它们。
我想问一下具体是怎么做到的?那些甚至 CardViews
?
我无法找到更多关于它们的信息,因为我不知道 View
的确切名称,所以如果有人可以指导我使用代码示例,我将不胜感激。
图片示例:
您可以使用此代码,这可能会有所帮助
<android.support.v7.widget.CardView
android:id="@+id/cardview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_large"
android:layout_marginRight="@dimen/margin_large"
android:elevation="100dp"
card_view:cardBackgroundColor="@android:color/white"
card_view:cardCornerRadius="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center_vertical"
android:paddingLeft="25dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Conversations" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@android:color/darker_gray" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="30dp"
android:paddingTop="20dp"
android:paddingBottom="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="game" />
...
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
显示的屏幕截图显示了一个普通的 CardView,其中的视图作为分隔符。
如果您搜索类似的东西,则没有 DividerView 或类似的东西。只需使用带有高度和背景的简单 View
。
我的图书馆里有类似的东西。我用它来创建分隔线:
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/stroke"/>
card_library.xml
<?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:paddingBottom="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="@+id/libraryname"
style="@style/CardTitle"
android:fontFamily="sans-serif-condensed"
android:textStyle="normal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"/>
<TextView
android:id="@+id/libraryversion"
style="@style/CardTitle"
android:fontFamily="sans-serif-condensed"
android:textStyle="normal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_marginTop="4dp"
android:gravity="left|bottom"
android:maxLines="1"
android:textSize="12sp"/>
<TextView
android:id="@+id/librarycreator"
style="@style/CardTitle"
android:fontFamily="sans-serif-condensed"
android:textStyle="normal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:gravity="right"
android:maxLines="2"
android:textSize="14sp"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="4dp"
android:background="@color/stroke"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:padding="4dp">
<TextView
android:id="@+id/description"
style="@style/CardText"
android:fontFamily="sans-serif-condensed"
android:textStyle="normal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:maxLines="20">
</TextView>
</LinearLayout>
</LinearLayout>
它将看起来像这样:
设置 app:cardElevation="0dp" 然后使用视图 - 见下文
<android.support.v7.widget.CardView
android:id="@+id/cv"
xmlns:android="http://schemas.android.com/apk/res/android"
app:cardElevation="0dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">
<!-- Insert UI elements -->
<View
android:layout_width="fill_parent"
android:background="@android:color/darker_gray"
android:layout_height="2dp"/>
</android.support.v7.widget.CardView>