【问题标题】:Android layout - alignment issue with ImageViewAndroid 布局 - ImageView 的对齐问题
【发布时间】:2009-03-17 20:56:32
【问题描述】:

我试图将图像放在LinearLayout 的左上角,但图像边框和填充占据了整个窗口的宽度。

如果我尝试下面的 XML,我会得到我的图像,其边框和整个页面宽度上的白色背景,除了图像最终居中 ,并且不会向左移动。

<ImageView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="left"
    android:src="@drawable/banner"
    android:background="@android:color/white"
    android:padding="@dimen/d_8px"
/>

layout_width 设置为fill_parent 时,是否有一些我尚未发现的属性强制图像在ImageView 内左对齐?

与此同时,我通过将 ImageView 放入另一个 LinearLayout 并在其右侧放置一个空的 TextView 来解决此问题,从而占据了其余的水平空间。

【问题讨论】:

    标签: android layout android-imageview


    【解决方案1】:

    我遇到了类似的问题,你今天早些时候回复了。这是 Eclipse 插件与 XML 编辑器并排提供的“屏幕设计”查看器,还是您在实际运行应用程序时遇到对齐问题?如果是前者,那就是插件的bug,如果是后者,请尝试添加:

    android:scaleType="fitStart"
    

    从我阅读的文档来看,这似乎最接近您的需要。

    【讨论】:

    • 这似乎确实可以解决问题。因为根本不使用 ImageView 并使用 TextView 的 drawableLeft 属性:)
    • 谢谢...效果很好,节省了我自己问这个问题的时间
    • fitEnd 会让它坐在底部...这是我在同一系列的东西中没有按预期工作的难题
    • @executor21:你救了我的命。谢谢
    • 我有一个图像视图,它只是不想承认 alignparentleft,但使用 fitstart 它做到了 =/
    【解决方案2】:

    只需在布局 XML 文件中配置 ImageView,如下所示:

                                <ImageView android:id="@+id/imageViewName" 
                                android:layout_width="90dp" 
                                android:layout_height="90dp" 
                                android:scaleType="fitStart" 
                                android:adjustViewBounds="true" 
                                android:padding="10dp" 
                                android:src="@drawable/ic_contact_picture"
                                android:background="@color/white" />
    

    【讨论】:

      猜你喜欢
      • 2014-03-05
      • 2014-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-08
      • 1970-01-01
      相关资源
      最近更新 更多