Android ImageView 布局重力不起作用
大家好,我没有这个问题的答案。希望你能帮忙。当我将比例类型属性设置为矩阵时,layout_gravity 属性作为中心它不起作用。而且我还在该图像视图中使用捏缩放。所以如果我可以设置图像并设置图像是否很小那么那就很好了。希望得到更好的回应。提前致谢...
编辑#1: 我的图像视图如下:
<?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>
hi guys i don't have the answer for this question. Hope you could help. layout_gravity property as center it is not working when i set the scale type property to matrix. And also i am using the pinch zoom for that imageview. so if i can set the image and set if the image is small then it would be very fine. Hoping for the better responses. Thanks in Advance...
Edit #1:
My ImageView follows:
<?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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
问题是您的 LinearLayout 是水平的,并且子项的宽度是 fill_parent 。因此,除非您将宽度指定为wrap_content并将其与水平中心对齐,否则它将不起作用。
The problem is your linearLayout is horizontal , and the child has fill_parent as it's width. so unless, you specify the width as wrap_content and align it to center horizontal, it won't work.
在 android xml 中试试这个
Try this in the android xml
使用重力代替布局重力
Use gravity instead of Layout Gravity