如何创建这样的布局

时间:2018-08-02 16:56:50

标签: android layout

如何使用android studio中的回收站视图制作这样的布局。 我无法获得确切的输出。

这是我的示例图片:

enter image description here

这是我的回收者视图代码示例。 如果图像不符合卡片视图布局,我将看不到图像

FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_gravity="top"
android:paddingTop="20dp"
android:orientation="horizontal">
<ImageView
    android:id="@+id/profile_photo"
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:paddingTop="20dp"
    android:layout_gravity="bottom|end"
    android:contentDescription="@string/cd_profile_picture"
    android:scaleType="center"
    android:src="@mipmap/ic_launcher_round"
    tools:layout_editor_absoluteX="0dp"
    tools:layout_editor_absoluteY="0dp" />



<android.support.v7.widget.CardView
    android:id="@+id/card_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    card_view:cardUseCompatPadding="true"
    card_view:cardBackgroundColor="@android:color/white">




<TextView
    android:id="@+id/comment_text"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:layout_marginStart="50dp"
    android:textColor="@color/black"
    tools:layout_editor_absoluteX="8dp"
    tools:layout_editor_absoluteY="0dp"
    tools:text="me" />

1 个答案:

答案 0 :(得分:0)

如果我正确理解了您的问题,则希望ImageView在CardView上方。只需在FrameLayout中切换位置即可实现。 在FrameLayout中,第二个子项(布局)显示在第一个子项(布局)上方,而第三个子项(布局)显示在第二个子项(布局)上方,依此类推。将ImageView以XML或层次结构放置在CardView下会导致图像显示在CardView上方。

相关问题