繁体   English   中英

Android:在图片下方添加文字

[英]Android: Adding text below an image

我正在尝试拟合图像,并在其下面有一些黑色背景和白色文本的布局。 我的问题是布局最终在图像和文本本身之间留下了空间,我不明白为什么:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <ImageView
        android:id="@+id/image"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scaleType="fitStart" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="15dp"
        android:layout_below="@+id/image" >

        <TextView
            style="@style/text_overlay"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

         <!-- Couple more elements -->

    </RelativeLayout>
</RelativeLayout>

我希望第二个15dp的RelativeLayout接触图像的底部,但是除非我将图像高度更改为较小的值,否则它会留一些空间。 此布局指定了如何显示图像及其下方的一些文本,但是我总共有4张图像使用此布局以2x2的显示方式加载到屏幕上。 (每个图像占据屏幕的25%)。

任何想法如何使RelativeLayout与图像的底部完全对齐?

尽管我认为您可能会看看我的Newspaper Puzzles应用程序的启动器布局,但我并没有完全理解您的问题...

或从开放数独游戏中查看此处找到的数字键盘布局:

如果可能的话,最好使用ADT工具获得正确的布局,但是我知道有时很难用它来获得特定的结果,我仍然建议使用Android开发工具中包含的xml工具。

如果您尝试将文本直接放在ImageView下方,建议使用复合可绘制对象。

有关更多详细信息,请参见以下问题: 如何使用复合可绘制对象而不是包含ImageView和TextView的LinearLayout

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM