【发布时间】:2018-07-31 08:46:01
【问题描述】:
我有一个相对布局,我想在其中显示一个 Imageview 和一个 TextView 和 background-image。
如果我没有使用任何margin-top,它会按我应该的方式工作,但如果我增加 ImageView 的上边距,图像会变小。
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/playerNameEnd"
android:layout_width="200dp"
android:layout_height="80dp"
android:background="@drawable/casino2"
android:gravity="center"
android:text="Player"
android:textColor="@color/cream"
android:textSize="26sp" />
<ImageView
android:id="@+id/roulette_EndPic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
app:srcCompat="@drawable/casino" />
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
【问题讨论】:
-
如果您没有从中受益,为什么还要使用
ConstraintLayout?由于您的ImageView的宽度和高度是wrap_content并且您的根布局不是ScrollView,因此它会尝试将所有内容都放在屏幕上,并且当您添加边距时,图像会变小。请注意,ImageView周围可能有填充 -
您希望看到什么?如果添加上边距,那么用于绘制图像的空间就会减少,对吧?
-
去掉约束布局部分,从相对布局开始。
标签: java android android-layout margin android-relativelayout