【问题标题】:Imageview width match_parent and need to horizontal centerImageview 宽度 match_parent 并且需要水平居中
【发布时间】:2014-12-10 07:16:47
【问题描述】:

我有高度和宽度为 match_parent 的 Imageview。我需要水平中心的图像没有将宽度更改为 wrap_content。您可以更改父布局。

这是我的 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" >



  <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="matrix"
        android:src="@drawable/ic_launcher" />

</RelativeLayout>

【问题讨论】:

  • 只需将 android:layout_centerHorizo​​ntal="true" 属性添加到

标签: android android-layout android-imageview


【解决方案1】:
<ImageView    android:id="@+id/imageView1"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:scaleType="fitCenter"
   android:src="@drawable/ic_launcher" />

这应该满足您的需要,如果您需要更多信息,请查看:scaletype description

试试下面的代码:

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:src="@drawable/ic_launcher" />

</RelativeLayout>

【讨论】:

  • 我需要水平中心的图像,而不是父中心的图像。
  • android:layout_width="fill_parent" android:layout_height="fill_parent" 试试这个。你会明白的,附言你试过这个链接吗,它解释得很好。
  • 我试过链接。 fill_parent 和 match_parent 是一样的。我也试过 fitStart。图片只在水平中心,不需要垂直中心。
  • 您能否发布您的问题的屏幕截图。
【解决方案2】:

你应该试试android:scaleType="fitCenter"。休息取决于您的确切需求以及您显示的图像大小。

For More Info

编辑

如果您只想将 ImageView 中的图像居中水平居中,请添加以下内容,

android:layout_centerHorizontal="true"

你的身高应该是wrap_content

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:scaleType="centerInside"
    android:src="@drawable/ic_launcher" />

【讨论】:

  • 我只需要水平中心的图像,而不是父中心的图像
  • @SamP 为什么需要图片的高宽为match_parent?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-07-18
  • 2014-06-26
  • 2021-08-07
  • 2011-03-18
  • 2013-11-14
  • 2013-04-17
  • 1970-01-01
相关资源
最近更新 更多