【问题标题】:how to make ImageView which is between two elements to margin left of the 'left element' using RelativeLayout?如何使用RelativeLayout制作位于两个元素之间的ImageView到“左元素”的左边距?
【发布时间】:2021-05-27 02:22:13
【问题描述】:

我想要的是让'6.4 MB' TextView 和'···'TextView 之间的'edit' ImageView,并让'edit' ImageView 接近'···'TextView。

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_marginTop="15dp"
    android:layout_height="match_parent">
    <ImageView
        android:src="@drawable/screenshot"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:id="@+id/screenShot"
        android:layout_alignParentLeft="true"
        android:layout_marginRight="10dp"
        />

    <TextView
        android:text="Video Name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="0dp"
        android:textSize="23dp"
        android:textColor="#000000"
        android:id="@+id/videoName"
        android:layout_toRightOf="@id/screenShot"
        android:layout_alignParentTop="true"
         />

    <TextView
        android:text="2021.05.19 · 5:11"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="0dp"
        android:textSize="15dp"
        android:textColor="#797675"
        android:id="@+id/recordDate"
        android:layout_toRightOf="@id/screenShot"
        android:layout_below="@id/videoName"
          />

    <TextView
        android:text="6.4 MB"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="0dp"
        android:textSize="15dp"
        android:textColor="#797675"
        android:id="@+id/videoSize"
        android:layout_toRightOf="@id/screenShot"
        android:layout_alignBottom="@id/screenShot"
        />

    <ImageView
        android:src="@drawable/edit"
        android:layout_width="27dp"
        android:layout_height="27dp"
        android:id="@+id/edit"
        android:layout_toRightOf="@id/videoSize"
        android:layout_toLeftOf="@id/edit"
        android:layout_alignBottom="@id/screenShot"
        />

    <TextView
        android:text="···"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="0dp"
        android:textSize="40dp"
        android:textColor="#000000"
        android:id="@+id/moreAction"
        android:layout_alignBottom="@id/screenShot"
        android:layout_alignParentRight="true"
        />
</RelativeLayout>


如果我在 'edit' ImageView 中使用 android:layout_marginLeft="40dp",那么 'edit' ImageView 将消失。
为什么 android:layout_marginLeft 注意到工作?
有人可以帮忙吗?

【问题讨论】:

    标签: android-layout android-relativelayout


    【解决方案1】:
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    
    <ImageView
        android:id="@+id/screenShot"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_alignParentLeft="true"
        android:layout_marginRight="10dp"
        android:src="@drawable/ic_launcher_background" />
    
    <TextView
        android:id="@+id/videoName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="0dp"
        android:layout_toRightOf="@id/screenShot"
        android:text="Video Name"
        android:textColor="#000000"
        android:textSize="23dp" />
    
    <TextView
        android:id="@+id/recordDate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/videoName"
        android:layout_marginLeft="0dp"
        android:layout_toRightOf="@id/screenShot"
        android:text="2021.05.19 · 5:11"
        android:textColor="#797675"
        android:textSize="15dp" />
    
    <TextView
        android:id="@+id/videoSize"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@id/screenShot"
        android:layout_marginLeft="0dp"
        android:layout_toRightOf="@id/screenShot"
        android:text="6.4 MB"
        android:textColor="#797675"
        android:textSize="15dp" />
    
    **<ImageView
        android:id="@+id/edit"
        android:layout_width="27dp"
        android:layout_height="27dp"
        android:layout_alignBottom="@id/screenShot"
        android:layout_marginRight="16dp"
        android:layout_toLeftOf="@id/moreAction"
        android:src="@drawable/ic_baseline_content_cut_24" />**
    
    <TextView
        android:id="@+id/moreAction"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@id/screenShot"
        android:layout_alignParentRight="true"
        android:layout_marginLeft="0dp"
        android:text="···"
        android:textColor="#000000"
        android:textSize="40dp" />
    

    【讨论】:

      【解决方案2】:

      我会删除

      android:layout_toLeftOf="@id/edit"
      

      并添加

      android:layout_marginLeft="170dp"
      

      完整的“编辑”ImageView 代码如下:

      <ImageView
                  android:src="@drawable/edit"
                  android:layout_width="27dp"
                  android:layout_height="27dp"
                  android:id="@+id/edit"
                  android:layout_toRightOf="@id/videoSize"
                  android:layout_marginLeft="170dp"
                  android:layout_alignBottom="@id/screenShot"
                  />
      

      【讨论】:

        猜你喜欢
        • 2013-04-30
        • 2017-06-25
        • 2015-10-25
        • 2013-11-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-04-22
        相关资源
        最近更新 更多