【问题标题】:NetworkImageView to occupy full width of screenNetworkImageView 占据整个屏幕宽度
【发布时间】:2015-08-26 16:04:24
【问题描述】:

我正在使用 com.android.volley.toolbox.NetworkImageView。 图片来自网址。 我想显示图像,使其宽度占据屏幕的整个宽度而不是高度,因为在图像下方有一个 Textview 的标题。

这是活动的xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/black"
tools:context=".MainActivity" >

<android.support.v4.view.ViewPager
    android:id="@+id/view_pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
</RelativeLayout>

这里是项目 xml。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" >

<com.android.volley.toolbox.NetworkImageView
    android:id="@+id/photo_image"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="1dp"
    android:src="@drawable/button_register" />

<TextView
    android:id="@+id/caption"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/photo_image"
    android:layout_marginLeft="15dp"
    android:text="Check"
    android:textColor="@color/white" />
</RelativeLayout>

从后端图像大小为 300 X 200 像素。 如何设置 imageview 以便它可以占据屏幕的整个宽度。 有人可以帮忙吗?

【问题讨论】:

    标签: android android-layout android-volley


    【解决方案1】:

    NetworkImageView 扩展了ImageView,因此您应该能够使用与ImageView 一起使用的所有内容。

    因此,如果您希望图像占据全宽并调整其高度以保持其纵横比(至少我理解您想要这样做),请使用 adjustViewBounds 属性

    您的 xml 将如下所示:

    <com.android.volley.toolbox.NetworkImageView
        android:id="@+id/photo_image"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="1dp"
        android:src="@drawable/button_register"
        <!-- add adjustViewBounds -->
        android:adjustViewBounds="true" />
    

    【讨论】:

      猜你喜欢
      • 2020-11-29
      • 2019-08-06
      • 1970-01-01
      • 1970-01-01
      • 2017-01-24
      • 1970-01-01
      • 2021-04-05
      • 1970-01-01
      • 2021-08-24
      相关资源
      最近更新 更多