首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >安卓:框架布局- ImageView高度不适合

安卓:框架布局- ImageView高度不适合
EN

Stack Overflow用户
提问于 2017-03-14 13:20:13
回答 3查看 1.3K关注 0票数 0

我有一个带有ImageView和TextView的框架布局。我打算把这段文字放在图片的中央。问题是图像不适合,ImageView不会包装内容的高度好。看看这幅画:

我需要它看起来像这样:

我尝试混合高度和(包装内容和匹配父母),但图片仍然不适合。这是xml:

代码语言:javascript
运行
复制
<FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            card_view:srcCompat="@drawable/tvrdjava"
            android:id="@+id/imageView3" />

        <TextView
            android:text="TextView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/textView6"
            android:textAlignment="center"
            android:textColor="@android:color/white"
            />

</FrameLayout>

图片位于不同分辨率的可绘制文件夹中(hdpi、mdpi、xhdpi、xhdpi、xxhdpi )。

EN

回答 3

Stack Overflow用户

发布于 2017-03-14 14:36:14

您应该尝试使用类似的方法,而不是使用RelativeLayout

代码语言:javascript
运行
复制
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        app:srcCompat="@drawable/ok"/>

    <TextView
        android:id="@+id/editText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:textSize="30sp"
        android:text="TextView"/>

</RelativeLayout>
票数 2
EN

Stack Overflow用户

发布于 2017-03-14 14:56:08

感谢@MatPag的想法。将此帧布局放置在LinearLayout (垂直)中是可行的。

代码语言:javascript
运行
复制
 <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:srcCompat="@drawable/tvrdjava"
            android:id="@+id/imageView8"
            android:adjustViewBounds="true"
            android:cropToPadding="false" />

        <TextView
            android:text="TrTemp"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/textView3"
            android:textColor="@android:color/holo_blue_dark"
            android:textAlignment="center"
            android:gravity="center"
            />

    </FrameLayout>
票数 1
EN

Stack Overflow用户

发布于 2017-08-21 11:16:01

这对我有用。

代码语言:javascript
运行
复制
             <FrameLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content">

                <ImageView
                    android:id="@+id/homepage_background_imageView"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_weight="1"
                    android:adjustViewBounds="true"
                    android:src="@drawable/background_homepage"/>

            </FrameLayout>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42787161

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档