【发布时间】:2017-02-15 10:49:22
【问题描述】:
实际上,我正在研究一种布局,我必须将 CardView 放在 ImageView 上,它只覆盖 ImageView 的一半,还添加一个 TextView(检查附加图像)。
注意:
- 我尝试使用 FrameLayout 以及相对布局... 我实现了它,但我认为它不是正确的方法,因为我主要是硬编码参数。
xml代码:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/toolbar">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="170dp"
android:layout_gravity="center"
android:background="@drawable/background"
android:id="@+id/picture">
</ImageView>
<TextView
android:text="TEXT VIEW"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="149dp"
android:layout_marginStart="149dp"
android:layout_marginTop="24dp"
android:id="@+id/textView" />
</FrameLayout>
</LinearLayout>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="120dp"
app:cardBackgroundColor="@color/textViewBackground"
card_view:cardUseCompatPadding="true"
android:layout_centerHorizontal="true"
card_view:cardElevation="15sp"
android:layout_marginTop="153dp" />
【问题讨论】:
-
您尝试过吗?如果是,则发布xml代码
-
请检查我的代码
-
嘿兄弟,你在代码中给出了硬编码的边距
-
详细告诉我您希望它如何实现,我会相应地向您发送代码。我在您编辑之前发布了该代码
-
实际上我的代码运行良好,但在我的代码中我在cardview中添加了
android:layout_marginTop="153dp"...所以当我检查不同的手机时它会产生差异边距...所以有什么办法可以避免这个问题
标签: android xml android-layout android-relativelayout android-framelayout