TextView 和 ImageView 之间的距离

Distance Between TextView and ImageView

这是片段的布局(附在主Activity上):

<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"
    tools:context="com.carbos.user.nameapp.Class"
    android:orientation="vertical">

    <!-- TODO: Update blank fragment layout -->
    <TextView
        style="@style/title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/title"
        android:layout_alignParentTop="true"/>

    <ImageView
        android:id="@+id/image"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="0dp"
        android:layout_below="@id/title"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/desc"
        android:layout_below="@id/image"/>
</RelativeLayout>

但是TextView和ImageView之间的距离不是0dp,也没有@id/desc。 这是输出(例如图像和标题):

这是 Drawable 中的图像:

如何设置 TextView 和 ImageView(以及 @id/desc 的 TextView)之间的距离?我尝试使用 LinearLayout,但它不起作用

我的猜测是textview和imageview之间没有距离。您看到的间隙是图像中的白色 space。 要验证这个理论,请尝试设置 imageview 背景而不是源。

您应该尝试将 ImageView 的 ScaleType 更改为其他内容。可能是 CenterCrop。有关详细信息,请参阅:http://developer.android.com/reference/android/widget/ImageView.ScaleType.html

试试这个:

<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"
tools:context="com.carbos.user.nameapp.Class"
android:orientation="vertical">

<!-- TODO: Update blank fragment layout -->
<TextView
    style="@style/title"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/title"
    android:layout_alignParentTop="true"/>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="200dip">
<ImageView
    android:id="@+id/image"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_below="@id/title"/>
 </RelativeLayout>

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/desc"
    android:layout_below="@id/image"/>
</RelativeLayout>