【问题标题】:Android Relative Layout Padding IssuesAndroid 相对布局填充问题
【发布时间】:2013-09-27 20:25:44
【问题描述】:

我查找了类似的问题,但他们的解决方案不起作用。我的相对布局正在添加左填充。

这是我的 XML:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:orientation="vertical" >

    <RelativeLayout 
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:layout_margin="0dp"
         android:fillViewport="true"
         android:padding="0dp" >

        <ImageView
            android:id="@+id/imageViewUserProfile"
            android:layout_width="114dp"
            android:layout_height="98dp"
            android:layout_alignParentTop="false"
            android:layout_margin="0dp"
            android:adjustViewBounds="true"
            android:padding="0dp"
            android:src="@drawable/default_t" />

        <TextView
            android:id="@+id/textViewUserProfileName"
            android:layout_width="fill_parent"
            android:layout_height="44dp"
            android:layout_alignParentTop="true"
            android:layout_centerVertical="true"
            android:layout_toRightOf="@id/imageViewUserProfile"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <TextView 
            android:id="@+id/textViewUserProfileHighlights"
            android:layout_width="fill_parent"
            android:layout_height="30dp"
            android:layout_toRightOf="@id/imageViewUserProfile"
            android:layout_below="@id/textViewUserProfileName"/>
    </RelativeLayout>

</LinearLayout>

我删除了父级 LinearLayout 以仔细检查左侧填充是否至少来自 RelativeLayout 块。我已经尝试了大多数对其他人有用的方法。任何帮助或建议将不胜感激。

【问题讨论】:

  • 可以加图片吗?
  • 我试过,但我没有足够的图像声誉=(基本上,当我从 Eclipse android xml 编辑器上的图形布局中选择相对布局时,它会选择父级的整个宽度(线性布局),但它为左填充增加了一些 dp,因此我的图像应该在左上角,但左边有一点空间
  • 你能给我发一张图片 RSenApps@gmail.com 吗?
  • 已发送电子邮件,如果需要更多信息,我可以发送更大的照片。感谢您的宝贵时间

标签: android android-relativelayout padding


【解决方案1】:

对于ImageView设置alignParentTop和alignParentLeft为true也去掉LinearLayout,没必要。

【讨论】:

  • 尝试将顶部和左侧对齐为真无济于事。我在相对布局下方添加了两个片段,我想通过中间分割屏幕,这就是我放置父线性布局的原因
  • 如果您删除 2 个文本视图,问题是否仍然存在?
  • 是的,图像是我相对布局中的第一项,并且从一开始它就有填充
  • 如果去掉listview的所有属性,改成wrap_contents,还会出现吗? Eclipse 中的渲染器也经常关闭,因此请尝试使用模拟器
  • listview 是指相对布局吗?我也在手机上调试它(galaxy s2 android 2.3)
猜你喜欢
  • 2011-10-28
  • 1970-01-01
  • 2012-02-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-12
  • 2011-03-18
相关资源
最近更新 更多