【问题标题】:set position of image in gallery android在画廊 android 中设置图像的位置
【发布时间】:2013-10-14 17:01:07
【问题描述】:

我有一个带有画廊的 android 应用程序。当应用程序在屏幕中间运行图像视图时,输入我想从屏幕左侧开始视图。

我尝试了所有的布局参数,如 padding、margin、gravity 和 setSpacing,但都无法将图像的位置设置为线性布局的左上角。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="0dp"
android:orientation="vertical" >

<uk.co.senab.photoview.sample.HackyViewPager
    android:id="@+id/view_pager"
    android:layout_width="match_parent"
    android:layout_height="404dp"
    android:layout_weight="3" />

<RelativeLayout
    android:id="@+id/actionBar"
    android:layout_width="fill_parent"
    android:layout_height="50dp"
    android:orientation="horizontal" >

    <Gallery
        android:id="@+id/gallery1"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:layout_gravity="left|top"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" />

</RelativeLayout>

【问题讨论】:

  • 那么您还没有显示您的布局文件进行调整。

标签: android


【解决方案1】:

1) 你需要RelativeLayout 作为父母。

2) 为您的图像视图设置属性

android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"

附言显示布局的 xml 代码

【讨论】:

  • ImageView imageView = new ImageView(_context); RelativeLayout.LayoutParams params1 = new RelativeLayout.LayoutParams(175,75); params1.addRule(RelativeLayout.ALIGN_PARENT_LEFT,RelativeLayout.TRUE); imageView.setImageResource(imageIds[postion]); imageView.setScaleType(ScaleType.FIT_XY); imageView.setLayoutParams(params1);
  • @KhaledHayek 什么类型的布局是父布局?线性还是相对?只有相对而言,您才能做到这一点。
猜你喜欢
  • 2020-12-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-10
  • 2016-11-26
  • 2013-02-25
  • 2013-11-20
相关资源
最近更新 更多