【问题标题】:How to solve wrong HEIGHT of IMAGEVIEW in percentage in Android如何在Android中以百分比解决IMAGEVIEW的错误高度
【发布时间】:2016-03-02 01:37:34
【问题描述】:

我已经尝试了一些想法来实现以下目标:

对于描述:我想要一个带有 textview 的标题,它包裹在嚎叫页面上,在这个标题下方我想显示三个图像并排显示。它应该像一个图片库。我想复制这个布局。

但我的问题是,我的 ImageView 的高度太高,并且尺寸大小的图像和标题之间存在距离。见图。

左边是我想要的,右边是我得到的......

这是我的布局代码:

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:scrollbars="none"
    android:layout_weight="1">


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

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorPrimary"
            android:textStyle="bold"
            android:text="titel"
            android:id="@+id/titel"
            android:gravity="center"
            android:padding="3dp"
            android:textSize="18sp"/>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/titel">

        <ImageView
            android:layout_width="0dp"
            android:layout_weight="0.208"
            android:layout_height="match_parent"
            android:id="@+id/image1"
            android:src="@drawable/1"/>

        <ImageView
            android:layout_width="0dp"
            android:layout_weight="0.389"
            android:layout_height="match_parent"
            android:id="@+id/image2"
            android:src="@drawable/2"/>

        <ImageView
            android:layout_width="0dp"
            android:layout_weight="0.403"
            android:layout_height="match_parent"
            android:id="@+id/image3"
            android:src="@drawable/3"/>

        </LinearLayout>

    </RelativeLayout>

</ScrollView>

【问题讨论】:

    标签: android imageview height android-linearlayout percentage


    【解决方案1】:

    我最好的猜测是因为您的 ImageView 以适合视图中心的方式缩放您的图像,并在视图的顶部和底部留下空白空间。尝试将 android:adjustViewBounds="true" 添加到 xml 中的 ImageView。

    附带说明,在调试视图层次结构时,转到Android Device Monitor,在右侧选择您的设备,然后单击Dump View Hierarchy for UI Automator,几乎总是会有所帮助。通过将鼠标悬停在不同的视图元素上,您可以轻松找出哪个视图占用了额外的空间。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-23
      • 2011-09-06
      • 1970-01-01
      • 2013-05-19
      • 2017-03-03
      • 1970-01-01
      • 2013-05-13
      • 1970-01-01
      相关资源
      最近更新 更多