Android ImageView 布局重力不起作用

标签 android layout imageview gravity

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

编辑 #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>

最佳答案

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

关于Android ImageView 布局重力不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8240814/

相关文章:

java - Android 监听器(读取小米波段传感器数据)

android - 带有复选框行的 ExpandableListView OnChildClickListener 在滚动时不会触发

python - PyQt - 减少小部件*扩展*布局中的边距和间距

java - ImageView 折叠并且不显示创建的缩略图

Android - 3D "stacked"图库图像

android - 在相对布局 Android 中动态显示多个 ImageView

android - 使用isbndb android提取书籍封面

android - FragmentDialog 中的 AlertDialog setTitle() 和 setMessage 等效项

layout - 使用 CSS3 计算值

html - CSS - 带 float 的流体 3 列布局