有人能帮助我吗?我的ImageView没有明显的原因获得巨大的间距。 XML:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/fragment_container_3"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_marginTop="50dp"
android:id="@+id/scroll"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/cv1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginBottom="6dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
card_view:cardElevation="10dp"
card_view:cardCornerRadius="4dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/img"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginBottom="0dp"
android:padding="0dp"
android:src="@drawable/list_cli2"
android:contentDescription="123" />
<TextView
android:id="@+id/totalCli"
android:layout_width="300dp"
android:paddingBottom="10dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:textColor="#fff"
android:layout_marginTop="10dp"
android:text="Total de Clientes: Buscando..."
android:textAllCaps="false"
android:textAppearance="@style/TextAppearance.AppCompat.Title" />
<com.github.mikephil.charting.charts.PieChart
android:id="@+id/cliChar"
android:layout_width="300dp"
android:layout_height="200dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="21dp" />
</RelativeLayout>
</android.support.v7.widget.CardView>
...
</RelativeLayout>
</ScrollView>
<android.support.design.widget.FloatingActionButton
android:id="@+id/refresh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom|right"
android:layout_marginRight="18dp"
android:layout_marginBottom="60dp"
android:clickable="true"
app:backgroundTint="@android:color/background_dark"
app:fabSize="normal"
app:srcCompat="@drawable/refresh"/>
</FrameLayout>
这样:
如果我将android:layout_height =“”设置为较低的值,键入200dp,则间距消失,但在这种情况下,在较小的设备上,视图将过时。已经尝试过:
将图像放置为LinearLayout
的背景,但间距均高于和低于。
将ImageView
置于LinearLayout
内但与上述相同。
有谁知道如何解决它?
如果我把它放在ScrollView外面,ImageView会在屏幕中间居中
答案 0 :(得分:1)
将此添加到您的imageview:
android:scaleType="centerCrop"
缩放类型属性将告诉图像应该如何适合可用空间。中心裁剪将使其填满整个空间,但作为交易,图像似乎会变焦。您可以尝试其他比例类型here。
答案 1 :(得分:0)
看起来你的list_cli2 drawable已经有了空格。通过图像编辑器打开它来检查它,看看是否有空白区域。