首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在android中,画廊图片从画廊中心开始

在android中,画廊图片从画廊中心开始
EN

Stack Overflow用户
提问于 2013-02-15 17:38:12
回答 1查看 789关注 0票数 0

我在两个按钮之间有一个图库,如下面的xml文件所示。在画廊中,图像是从中心添加的。

代码语言:javascript
复制
<RelativeLayout
      android:layout_height="80dp"
      android:layout_width="fill_parent"
      android:id="@+id/gal"
      android:layout_alignParentBottom="true"
      android:background="@drawable/backgroundblackwhite">
       <Button android:layout_height="wrap_content"
           android:layout_width="wrap_content"
           android:background="@drawable/backward"
           android:layout_alignParentLeft="true"/>
       <Button android:layout_height="wrap_content"
           android:layout_width="wrap_content"
           android:background="@drawable/forward"
           android:layout_alignParentRight="true"/>
      <Gallery 
          android:layout_height="100dp"
          android:layout_width="fill_parent"
          android:layout_alignParentBottom="true"
          android:id="@+id/gallary"
          android:layout_marginLeft="100dp"
          android:layout_marginRight="100dp"
          android:spacing="5dp"
          android:layout_marginBottom="10dp"
          android:background="@drawable/greypattren"/>  
   </RelativeLayout>

I want the images to start from Left of my Gallery. I used the below code to set the gallery images to start from the left of gallery view.

新指标= DisplayMetrics DisplayMetrics();getWindowManager().getDefaultDisplay().getMetrics(metrics);

代码语言:javascript
复制
            Gallery g = (Gallery) findViewById(R.id.gallery);

            // set gallery to left side
            MarginLayoutParams mlp = (MarginLayoutParams) g.getLayoutParams();
            mlp.setMargins(-(metrics.widthPixels / 2 + (imageWidth/2)), mlp.topMargin,
                        mlp.rightMargin, mlp.bottomMargin);

但是,我的图库在最左边,即在左边隐藏我的按钮(我应该用它来滚动图库)

我张贴两个图像的截图,1)画廊视图,我想从屏幕的左边添加图像。2)使用指标添加上述代码(设置边距)后,对图库进行更改。

我需要更改xml或代码中的任何内容吗?

请提前帮个忙谢谢

EN

回答 1

Stack Overflow用户

发布于 2013-02-15 19:35:12

替换

代码语言:javascript
复制
 MarginLayoutParams mlp = (MarginLayoutParams) g.getLayoutParams();
 mlp.setMargins(-(metrics.widthPixels / 2 + (imageWidth/2)), mlp.topMargin,
 mlp.rightMargin, mlp.bottomMargin);

代码语言:javascript
复制
mlp.setMargins((int) -(metrics.widthPixels/2.5), mlp.topMargin, mlp.rightMargin,                    mlp.bottomMargin);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14891776

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档