gpt4 book ai didi

android - ImageView 在方向更改期间不保持恒定高度

转载 作者:搜寻专家 更新时间:2023-11-01 09:31:28 25 4
gpt4 key购买 nike

我有一个 XML 布局,它有一个名为 cust_imgImageView,我可以在 ImageView 中放置任何尺寸的图像,但高度除外方向改变时宽度不能改变。目前这还没有发生,有人可以建议我如何实现这一目标吗?

我尝试应用以下 ScaleType

  • 居中
  • CENTER_CROP
  • CENTER_INSIDE
  • 健身中心
  • FIT_END
  • FIT_START
  • FIT_XY
  • 矩阵

它们都不起作用。

这是我的布局 XML:

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1"
android:background="@color/white">

<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.94"
android:fillViewport="true">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="1">

<LinearLayout
android:id="@+id/imglayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.3"
android:gravity="center_vertical"
android:orientation="vertical">

<ImageView
android:id="@+id/cust_img"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
android:adjustViewBounds="true"
android:maxHeight="150dp"
android:maxWidth="160dp" />
</LinearLayout>

<FrameLayout
android:id="@+id/frag_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.7"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
</FrameLayout>
</LinearLayout>
</ScrollView>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.06">
<include layout="@layout/footer_layout"/>
</LinearLayout>
</LinearLayout>

最佳答案

不是保持宽度与父级匹配,而是使用高度和宽度包裹内容。

使用图像 scale_type :CENTER_CROP

    <ImageView
android:id="@+id/cust_img"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
android:adjustViewBounds="true"/>

关于android - ImageView 在方向更改期间不保持恒定高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46931474/

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