gpt4 book ai didi

android - ImageView 中的填充不起作用

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:51:17 28 4
gpt4 key购买 nike

我想制作一个包含顶部栏和图像的屏幕。我将 TextView 用于顶部栏,将 ImageView 用于图像。我只想为 ImageView 设置填充。我的 xml 在下面给出。填充操作不起作用。谁能解释为什么以及该怎么做?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background" >

<TextView android:id="@+id/topBar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="@string/home"
android:textSize="20sp"
android:textColor="#ffffff"
android:textStyle="bold"
android:shadowColor="#000000"
android:shadowRadius="1"
android:shadowDy="-1"
android:gravity="center"
android:background="@drawable/navBar"/>

<ImageView android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:paddingRight="10dp"
android:paddingBottom="10dp"
android:layout_below="@+id/topBar"
android:background="@drawable/image"/>

</RelativeLayout>

最佳答案

您应该使用 layout_margin 而不是 padding 因此它应该如下所示:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background" >

<TextView android:id="@+id/topBar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="@string/home"
android:textSize="20sp"
android:textColor="#ffffff"
android:textStyle="bold"
android:shadowColor="#000000"
android:shadowRadius="1"
android:shadowDy="-1"
android:gravity="center"
android:background="@drawable/navBar"/>

<ImageView android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:layout_below="@+id/topBar"
android:background="@drawable/image"/>

并且您可以为所有方向指定 1 layout_margin,而不是使用

android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"

你可以使用:

android:layout_margin="10dip"

希望这就是您要找的。否则请给我反馈 ;)

更新

你可以设置cropToPadding还有:

<ImageView 
...
android:cropToPadding="true"
android:padding="15dp"
android:scaleType="centerInside"
...

关于android - ImageView 中的填充不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20172350/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com