Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/179.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 从某种角度看,额外8dp利润背后的原因是什么?不是解决问题的办法_Android_Android Layout_Android Xml - Fatal编程技术网

Android 从某种角度看,额外8dp利润背后的原因是什么?不是解决问题的办法

Android 从某种角度看,额外8dp利润背后的原因是什么?不是解决问题的办法,android,android-layout,android-xml,Android,Android Layout,Android Xml,在我的活动xml文件中,我在视图的左侧获得了一个额外的8dp边距(用下划线表示) 在“视图”中获得8dp额外利润的原因?(在TextView下加下划线。) 我在那个视图中给出了48dp的左边距 除此之外,我还有其他看法 非常感谢:-) 因为您的视图宽度是匹配父视图&android:layout\u marginLeft&android:layout\u gravity=“center” 正在导致视图移到屏幕边界之外 尝试从视图中删除重心布局(绘制线) 和使用 android:layou

在我的活动xml文件中,我在视图的左侧获得了一个额外的8dp边距(用下划线表示)

  • 在“视图”中获得8dp额外利润的原因?(在TextView下加下划线。)
  • 我在那个视图中给出了48dp的左边距
除此之外,我还有其他看法

  • 非常感谢:-)

    • 因为您的视图宽度是匹配父视图&
      android:layout\u marginLeft
      &
      android:layout\u gravity=“center”
      正在导致视图移到屏幕边界之外

      尝试从视图中删除重心布局(绘制线)

      和使用

      android:layout_marginLeft="@dimen/space_large"
      
      而不是

      android:layout_marginLeft="@dimen/space_xxlarge"
      

      您正在向图标添加可绘制的填充,而下划线和图标之间的边沿左侧完全不同。你还必须考虑图标本身的大小。我会很惊讶,它会有完全相同的对齐方式

      与此相反,为什么不在两个线性布局之间使用具有权重的水平线性布局,一个具有图标,另一个具有与下划线相同高度的透明视图,另一个线性布局包含完全对齐的文本和下划线。没有利润,什么都没有,只是重量的分配。大概是这样的:

      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="100dp"
          android:orientation="horizontal"
          android:weightSum="10">
      
          <LinearLayout
              android:layout_width="0dp"
              android:layout_height="match_parent"
              android:layout_weight="2"
              android:orientation="vertical">
      
              <ImageView
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content" />
      
              <View
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content" />
          </LinearLayout>
      
          <LinearLayout
              android:layout_width="0dp"
              android:layout_height="match_parent"
              android:layout_weight="8"
              android:orientation="vertical">
      
              <TextView
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:text="Account Information"
                  android:textSize="20sp" />
      
              <View
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content" />
      
          </LinearLayout>
      
      </LinearLayout>
      
      
      

      这只是一种可能的解决方案,可以保证精确对齐。

      根据以下两条线:

      android:drawableLeft="@drawable/ic_account_box_black_18dp"
      android:drawablePadding="@dimen/space_large"
      
      您将有一个宽度为
      18dp
      的可绘制区域,然后是一个
      @dimen/space\u large
      的填充区域,它看起来是
      24dp
      ,在
      TextView
      的左边缘和文本本身的开头之间总共有
      42dp
      的填充区域

      但是,您行中的
      布局\u marginLeft
      @dimen/space\u xxlarge
      48dp
      。由于一个是
      42dp
      ,另一个是
      48dp
      ,它们不会对齐。如果希望元素以可视方式显示在一行中,则需要更改其中一个。

      
      
      <View
                  android:layout_width="match_parent"
                  android:layout_height="1dp"
                  android:layout_gravity="center"
                  android:layout_marginLeft="48dp"
                  android:background="@android:color/darker_gray"/>
      
      布局中有多个视图,您正在使用布局\ u gravity=“center”。因此,
      视图
      正试图将自身调整到内部
      线性布局的中心位置
      。只需尝试删除
      layout\u gravity
      或使用
      layout\u gravity=“left”

      您已经添加了24dp的marginLeft和24dp的drawable padding,您说总共是48dp,但您忘记了drawable图标的宽度。因此,账户“A”的后一个账户的保证金不在48 DP

      您使用的是
      LinearLayout
      ,每一个都在左侧,因此不需要任何重力

      你还说从
      视图中移除重力会使它从左侧移动36 dp。是的,没错。计算中遗漏了可绘制图标的宽度


      设置
      View的
      layout\u margin
      等于
      48dp+图标宽度
      。我想这就是您得到的原因。

      因为您设置了下划线视图的布局\u width=“match\u parent”和布局\u gravity=“center”。
      后视图度量:
      -线性父视图的宽度为1080px
      -下划线视图的宽度为936px(因为布局_marginLeft=“48dp”(144px))
      查看布局时:
      -因为线性父对象的方向是“垂直的”,所以当设置layout_gravity=“center”与layout_gravity=“center\u horizontal”相等时,
      -对于“中心水平”子视图,线性父视图将子视图的X中心与其X中心相距
      因此下划线视图的X轴将为(px):
      540(父对象的X-中心)+144(左边缘48dp)-468(子对象宽度的一半)=216px(72dp)

      这就是为什么使用layout_gravity=“center”,您将看到下划线视图将获得24dp的额外边距

      只需删除



      android:layout\u gravity=“center”
      图像中的问题不清楚。线条之间的差异是8dp。@阿披舍克,请编辑图像并标记您面对问题的位置。你面对的问题是什么?如果是这样的话,你可以说,图像的左边有24dp的填充,文本视图的左边有24dp的填充。这就是48dp,你想让行从文本开始的地方开始吗?你有没有在真实的设备上测试过它,并确保你在那里也得到了同样的结果?@vamsichilla先生,这张快照来自genymotion。原因是。。?我给了背景色黑色。。我不是在寻找其他方式,我只是在寻找没有内部间距的原因空间大是24dp,空间大是48 dp,你的文本视图使用空间大是为什么?我不知道为什么我会得到8分的额外利润..?呵呵。。我花了很多时间。我知道其他的方法。但不知道为什么-/亲爱的andriodpotato7,我已经用其他方式对其进行了排序。。我只是在寻找原因。。不是其他的解决方案你用什么其他的方法解决了它?它可以是很多事情。它可以是字体大小,因为字体是粗体的,所以它推动了可绘制或其他东西,它可以是因为可绘制。正如我所说,用这种方式利用利润显然不是一个好的解决方案。办公室的先生们不会等我解决问题。我在问你你的解决方案是什么。也许在你的答案中有你问题的答案。那不是我问题的答案。。不是48dp。。我得到48+8=56dp。。当我将左边缘设置为48 dp。。先生,你能帮我解决一个问题吗。。或者帮我编辑一下。。请注意。。非常感谢。我正在使用布局重心。。但这并不意味着它将处于中心位置。bez am使用线性布局井,不提供布局重力。开始时是36分,但我给了48分的余量。再次出现另一个问题,为什么它在36dp之后开始。文本视图和标题等其他东西是否位于正确的位置?您的意思是只有您的分隔符
      视图
      未处于正确位置。。。对吧?我已经完成了那一页。通过调整文本视图中的可绘制填充8dp额外值。是
      
      android:layout_marginLeft="@dimen/space_xxlarge"
      
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="100dp"
          android:orientation="horizontal"
          android:weightSum="10">
      
          <LinearLayout
              android:layout_width="0dp"
              android:layout_height="match_parent"
              android:layout_weight="2"
              android:orientation="vertical">
      
              <ImageView
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content" />
      
              <View
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content" />
          </LinearLayout>
      
          <LinearLayout
              android:layout_width="0dp"
              android:layout_height="match_parent"
              android:layout_weight="8"
              android:orientation="vertical">
      
              <TextView
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:text="Account Information"
                  android:textSize="20sp" />
      
              <View
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content" />
      
          </LinearLayout>
      
      </LinearLayout>
      
      android:drawableLeft="@drawable/ic_account_box_black_18dp"
      android:drawablePadding="@dimen/space_large"
      
      <View
                  android:layout_width="match_parent"
                  android:layout_height="1dp"
                  android:layout_gravity="center"
                  android:layout_marginLeft="48dp"
                  android:background="@android:color/darker_gray"/>