gpt4 book ai didi

Android 自适应 ImageView 尺寸到屏幕尺寸

转载 作者:太空狗 更新时间:2023-10-29 14:24:45 29 4
gpt4 key购买 nike

我有一个想要实现的特定布局,但我不知道如何让它在多种屏幕尺寸上稳健地工作。

关键思想是 TextViews 中的信息很重要,而 ImageView 是装饰性的。我希望根据用户屏幕尺寸(最大尺寸)调整 ImageView 的大小。此外,我希望所有元素保持组合在一起,这样它们就不会在大屏幕上显得稀疏。我更愿意在 xml 中找到解决方案,但我愿意接受任何可以完成这项工作的方法。

这是我想要的(我还不能在这里发布图片):

在小屏幕上, ImageView 会缩小:

https://dl.dropbox.com/u/29549935/small_screen.png

在大屏幕上 imageview 满足最大值(应该通过自动缩放来处理),并且内容一起保持在屏幕的中心:

https://dl.dropbox.com/u/29549935/large_screen.png

我已经尝试了很多我认为应该可行的选项,例如,下面的代码将 TextView 相对于 ImageView 定位,所有这些都组合在一个相对布局中。这在大屏幕上效果很好,但是在小屏幕上, TextView 会被 ImageView 推开:

<RelativeLayout
android:id="@+id/container1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:orientation="vertical" >

<RelativeLayout
android:id="@+id/container2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:orientation="vertical">

<TextView
android:id="@+id/textview1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_above="@+id/imageview1"
android:gravity="center_horizontal"
android:text="@string/textview1" />

<ImageView
android:id="@+id/imageview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:gravity="center_horizontal"
android:adjustViewBounds="true"
android:maxHeight="256dp"
android:maxWidth="256dp"
android:minHeight="100dp"
android:minWidth="100dp"
android:scaleType="centerInside"
android:src="@drawable/mydrawable" />

<TextView
android:id="@+id/textview2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/imageview1"

android:gravity="center_horizontal"
android:text="@string/textview2" />

<TextView
android:id="@+id/textview3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textview2"
android:gravity="center_horizontal"
android:text="@string/textview3"/>
</RelativeLayout>
</RelativeLayout>

如果规定imageview可以在relativelayout中占一定比例,这种方式好像可以。

非常欢迎任何帮助。提前致谢。

最佳答案

为此,您必须为单独的屏幕分辨率创建图像并将其放入 drawable-ldpi、drawable-mdpi、drawable-hdpi、drawable-xhdpi 文件夹....`,例如

drawable-ldpi  - Low dpi  (Low size screen Resolution)

drawable-mdpi - Medium dpi (Medium size screen Resolution)

drawable-hdpi - High dpi, (large size screen Resolution)

drawable-xhdpi - Extended High dpi (For tablest and wide screen)

而且你还应该注 Intent 像的密度

multiple screen support

Sample App and ABout density etc ...

Multiple screen support design

关于Android 自适应 ImageView 尺寸到屏幕尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13588553/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com