Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在方向更改期间,ImageView不会保持恒定高度_Android_Android Imageview - Fatal编程技术网

Android 在方向更改期间,ImageView不会保持恒定高度

Android 在方向更改期间,ImageView不会保持恒定高度,android,android-imageview,Android,Android Imageview,我有一个XML布局,它有一个名为cust\u img的ImageView的ImageView,我可以在ImageView中放置任意尺寸的图像,但当方向改变时,高度和宽度不得改变。目前这种情况还没有发生,有人能建议我如何做到这一点吗 我尝试应用以下ScaleType值 居中 中心作物 中心内 健身中心 安装端 装配开始 适合 母体 他们都没有工作 以下是我的布局XML: <LinearLayout android:layout_width="match_paren

我有一个XML布局,它有一个名为
cust\u img
ImageView
ImageView,我可以在
ImageView
中放置任意尺寸的图像,但当方向改变时,高度和宽度不得改变。目前这种情况还没有发生,有人能建议我如何做到这一点吗

我尝试应用以下
ScaleType

  • 居中
  • 中心作物
  • 中心内
  • 健身中心
  • 安装端
  • 装配开始
  • 适合
  • 母体
他们都没有工作

以下是我的布局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>


您必须将固定高度设置为
ImageView
,否则将
wrap\u content
设置为
ImageView
宽度

使用此选项更改imageview代码

                          <ImageView
                            android:id="@+id/cust_img"
                            android:layout_width="wrap_content"
                            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" />


不要保持宽度匹配,而是同时使用高度和宽度换行内容

使用图像缩放类型:
居中裁剪

    <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"/>


不要保持宽度匹配,而是同时使用高度和宽度换行content@Praneeth不起作用\@BatCat当你改变你的方向时到底发生了什么?高度降低了。如果你删除了“最大宽度”和“最大高度”属性?删除了
android:layout\u weight=“0.3”
imgLayout的
成功了。@BatCat是的,使用重量会很好!如果你认为我的答案对你有帮助,请随意投票:P