You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android XML开发:如何将文本设置在图片正下方靠左位置

问题根因

你当前HorizontalScrollView内部的LinearLayout使用了水平排列方向,所有子控件默认会横向依次排布,因此「Your Story」文本会直接排在第一个头像的右侧,而非你期望的下方,这是布局结构逻辑错误,和边距、对齐属性设置无关。

修改方案

你需要把每一组「头像+用户名」的故事项单独用垂直方向的LinearLayout包裹,再放到水平滚动的父容器里,就能实现文本位于头像正下方的效果,修改后的核心代码如下:

<!-- 仅展示修改后的HorizontalScrollView部分,其余上层代码保持不变即可 -->
<HorizontalScrollView
    android:id="@+id/horizontalScrollView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="23dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/linearLayout"
    tools:ignore="SpeakableTextPresentCheck">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:paddingHorizontal="8dp">

        <!-- 你的故事项 -->
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:gravity="center_horizontal"
            android:layout_marginHorizontal="8dp">

            <ImageView
                android:id="@+id/imageView1"
                android:layout_width="70dp"
                android:layout_height="70dp"
                app:srcCompat="@drawable/playstore" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="6dp"
                android:text="Your Story"
                android:textSize="12sp"/>
        </LinearLayout>

        <!-- 其余故事项复制上述结构修改内容即可 -->
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:gravity="center_horizontal"
            android:layout_marginHorizontal="8dp">

            <ImageView
                android:id="@+id/imageView2"
                android:layout_width="70dp"
                android:layout_height="70dp"
                app:srcCompat="@drawable/playstore" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="6dp"
                android:text="用户昵称"
                android:textSize="12sp"/>
        </LinearLayout>
        
        <!-- 剩余所有头像都按照上述结构嵌套即可 -->

    </LinearLayout>
</HorizontalScrollView>

其余未展示的上层布局代码不需要改动,你原代码里给单个ImageView加的layout_weight属性没用,可以删掉。

内容的提问来源于stack exchange,提问作者ytsaxena

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.03 12:54:03