在 ImageView 后显示 TextView

6
我希望在我的Android屏幕上,ImageView之后显示TextView,但现在文本会覆盖图像。
布局:
<FrameLayout 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="in.sitemakers.sitemakers.AboutFragment">

<ImageView
    android:id="@+id/about_image"
    android:src="@drawable/sitemakers_laptops"
    android:layout_width="match_parent"
    android:scaleType="fitXY"
    android:layout_height="420dp" />

<TextView
    android:layout_below="@+id/about_image"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Site Makers is the web development company engage in the.."
    />

</FrameLayout>

Preview

请查看上面的截图,并帮助我以这样的方式更新我的XML,以便在ImageView之后出现TextView
3个回答

7
请用LinearLayoutRelativeLayout替换FrameLayout,因为FrameLayout会将视图放置在另一个视图之上。 LinearLayout:以线性方式放置子视图,水平或垂直一个接一个地排列。
注意:线性布局还可以根据分配的weight属性值动态地为子视图分配可用宽度和高度。 RelativeLayout: 一种布局,其中子项的位置可以相对于彼此或父项进行描述。
还有许多其他ViewGroups you can use,根据说明使用即可。

注意:不要使用px,而是使用dp,如android:layout_height="420dp",因为px表示实际屏幕像素,限制了在大屏幕上保持视图相同大小的能力(视图会很小),如密度无关性中所述。


@Pavneet_Singh 谢谢,RelativeLayout解决了这个问题。 - Amit Gupta
如果问题已经解决,请接受这个答案,@AmitGupta。 - UltimateDevil
@UltimateDevil,是的,我的亲爱的朋友,已经被接受了。Stackoveflow让我等一段时间,否则就会更早地接受 :) - Amit Gupta
@AmitGupta,我很高兴能够帮助你,祝你编程愉快,谢谢UltimateDevil。 - Pavneet_Singh
@Pavneet_Singh先生需要在这个问题上寻求帮助**question**。请您看一下。 - UltimateDevil

1

您可以使用orientation="vertical"的linearlayout,它很容易实现。


0

您可以使用 LinearLayoutRelativeLayout

如果您使用 LinearLayout,那么您可以设置 orientation="vertical"

如果您使用 RelativeLayout,那么您可以在 TextView 中使用 android:layout_below="@id/about_image"

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    orientation="vertical"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/about_image"
        android:src="@drawable/sitemakers_laptops"
        android:layout_width="match_parent"
        android:scaleType="fitXY"
        android:layout_height="420px" />

    <TextView
        android:layout_below="@+id/about_image"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Site Makers is the web development company engage in the.."/>

    </LinearLayout>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接