【问题标题】:Android ImageView layout gravity not workingAndroid ImageView布局重力不起作用
【发布时间】:2014-06-14 02:34:45
【问题描述】:

大家好,我没有这个问题的答案。希望你能帮忙。 layout_gravity 属性作为中心,当我将比例类型属性设置为矩阵时,它不起作用。而且我正在使用该图像视图的捏缩放。因此,如果我可以设置图像并设置图像是否很小,那就很好了。希望得到更好的回应。提前致谢...

编辑#1: 我的 ImageView 如下:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="@drawable/bg">

<LinearLayout android:layout_width="fill_parent"
    android:id="@+id/linear_titile_bar" android:layout_height="wrap_content"
    android:background="@drawable/top_black_logo_bg">

    <Button android:layout_width="wrap_content"   android:id="@+id/myphotos_gridview_back"
        android:layout_height="wrap_content" android:background="@drawable/back_gray_bt"
        android:layout_gravity="center_vertical" android:layout_margin="5dip">   </Button>
</LinearLayout>

<LinearLayout android:layout_width="fill_parent"
    android:id="@+id/nameTitlebar" android:layout_below="@+id/linear_titile_bar"
    android:layout_height="wrap_content" android:background="@drawable/title_gray_bg">

    <TextView android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:gravity="center"
        android:text="MY PHOTOS" style="@style/ivideodate.blue.large"></TextView>
</LinearLayout><!-- android:layout_above="@+id/FooterLayout" -->

<LinearLayout android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:layout_below="@+id/nameTitlebar"
    android:layout_above="@+id/FooterLayout" android:gravity="center">

    <ImageView android:layout_width="fill_parent" android:scaleType="matrix"
        android:layout_gravity="center" android:layout_height="fill_parent"
        android:id="@+id/ProfileImageView" />

</LinearLayout>

<LinearLayout android:layout_height="wrap_content"
    android:background="@drawable/my_photo_edit_but_bg"
    android:layout_width="fill_parent" android:layout_alignParentBottom="true"
    android:id="@+id/FooterLayout" android:orientation="vertical"
    android:gravity="center">

    <Button android:background="@drawable/set_profile_pic_bt"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:scaleType="fitCenter" android:id="@+id/setprofileimage" />
    <Button android:background="@drawable/delete_photo_bt"
        android:layout_width="wrap_content" android:layout_marginTop="5dip"
        android:layout_height="wrap_content" android:scaleType="fitCenter"
        android:id="@+id/deleteimage" />

</LinearLayout>

 </RelativeLayout>

【问题讨论】:

  • 邮政编码如何设置imageview的重力?
  • @user370305 我已经更新了我的问题...
  • 如果您不介意可以发布整个 xml 文件。
  • @user370305 嗨,我已经用完整的 xml 更新了我的问题...
  • 查看我的回答here。它帮助我集中了 Imageview。

标签: android layout imageview gravity


【解决方案1】:

问题是您的 linearLayout 是水平的,而孩子的宽度为 fill_parent。因此,除非您将宽度指定为 wrap_content 并将其对齐到水平居中,否则它将不起作用。

【讨论】:

  • 我不能使用 wrap_content,因为我使用的是捏缩放。如果图像尺寸大不会有问题,但如果图像尺寸小就会出现问题......
【解决方案2】:

在 android xml 中试试这个

      <?xml version="1.0" encoding="utf-8"?>
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent"
       android:orientation="vertical" >
       <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" 
        android:gravity="center">
        <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher" 
        />
        </LinearLayout>
        </LinearLayout>          

【讨论】:

    【解决方案3】:

    使用重力而不是布局重力

    【讨论】:

    • Imageview没有场重力,只有layout_gravity
    • Imageview没有场重力,只有layout_gravity
    猜你喜欢
    • 2013-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-28
    • 2021-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多