【问题标题】:Display TextView after ImageView在 ImageView 之后显示 TextView
【发布时间】:2022-02-11 02:12:01
【问题描述】:

我想在ImageView 之后显示TextView,但现在我的 Android 屏幕上的图像上出现了文本。

布局:

<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>

请查看上面的屏幕截图并帮助我更新我的 XML,以便 TextViewImageView 之后>.

【问题讨论】:

    标签: android android-layout textview imageview


    【解决方案1】:

    FrameLayout 替换为LinearLayoutRelativeLayout,因为FrameLayout 将视图一个接一个地放置

    LinearLayout : 以线性方式放置子视图,水平或垂直一个接一个。

    注意:线性布局还允许您根据分配的weight 属性值在子视图之间动态分配可用宽度和高度。

    RelativeLayout : 一个布局,其中子级的位置可以相互描述或与父级相关

    按照说明还有很多其他ViewGroups you can use

    注意:不要使用px 而是使用dp 作为android:layout_height="420dp",因为px 代表实际屏幕像素,限制在大屏幕上保持相同大小的视图(浏览量会很小),正如这里提到的Density independence

    【讨论】:

    • @Pavneet_Singh 谢谢,RelativeLayout 解决了这个问题。
    • @AmitGupta 如果问题得到解决,则接受此答案
    • @UltimateDevil 是的接受了我亲爱的朋友.. Stackoveflow 要求我等待某个时间,否则早些接受 :)
    • @AmitGupta 我很高兴能帮上忙,编码愉快,感谢 UltimateDevil
    • @Pavneet_Singh 先生需要这方面的帮助 question 。请看一次
    【解决方案2】:

    你可以使用带有orientation="vertical"的linearlayout,它真的很容易实现。

    【讨论】:

      【解决方案3】:

      您可以使用 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>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-12-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多