在android中有类似bootstrap面板和jumbotron的东西吗?

时间:2015-05-24 12:11:53

标签: android user-interface android-layout android-fragments android-xml

我对Android布局很新。

我正在创建一个需要一些有前途的布局和UI的Android应用程序。

需要类似bootstraps'panel panel-defaultjumbotron

我的要求在这张照片中清晰可见。

enter image description here

我们可以在Google Playstore应用以及whatsapp中看到它们。我已经对它进行了很多搜索,并尝试使用GridLayout背景(但没有阴影,看起来像平面图像),我希望我能在这里得到答案。

他们叫什么以及如何使用它们。请提及代码或提供参考。

提前致谢!!

2 个答案:

答案 0 :(得分:0)

我使用自定义xml drawable作为我的布局背景来提供类似的效果。

在drawable文件夹中创建一个名为card_background.xml的文件:

undefined

然后你需要定义两种颜色card_shadow&您的values / color.xml文件中的card_white:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
    <shape android:shape="rectangle" >
        <solid android:color="@color/background_material_light" />
    </shape>
</item>
<item
    android:bottom="3dp"
    android:left="5dp"
    android:right="5dp"
    android:top="4dp">
    <shape android:shape="rectangle" >
        <corners android:radius="2dp" />
        <solid android:color="@color/card_shadow" />
    </shape>
</item>
<item
    android:bottom="4dp"
    android:left="6dp"
    android:right="6dp"
    android:top="3dp">
    <shape android:shape="rectangle" >
        <corners android:radius="2dp" />

        <solid android:color="@color/card_white" />
    </shape>
</item>
</layer-list>

之后,您可以将您的drawable作为布局的背景传递,例如:

<color name="card_white">#ffffffff</color>
<color name="card_shadow">#CABBBBBB</color>

这应该可以解决问题

答案 1 :(得分:0)

您可以尝试使用CardView来实现。

CardView小部件是v7 Support Libraries的一部分。要在您的项目中使用它,请添加以下依赖项:

dependencies {
    implementation 'com.android.support:cardview-v7:28.0.0'
}

要使用CardView,您需要将其添加到布局文件中。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:card_view="http://schemas.android.com/apk/res-auto">

    <!-- A CardView that contains a TextView -->
    <android.support.v7.widget.CardView
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:id="@+id/card_view"
        android:layout_gravity="center"
        android:layout_width="200dp"
        android:layout_height="200dp"
        card_view:cardCornerRadius="4dp">

        <TextView
            android:id="@+id/info_text"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </android.support.v7.widget.CardView>
</LinearLayout>

有关更多自定义CardView的信息,请参见:https://github.com/gabrielemariotti/cardslib

相关问题