繁体   English   中英

如何在FrameLayout Android中将边距放置到imageview?

[英]How to put margins to a imageview in FrameLayout android?

我有一个蓝框。 红色和绿色以线性布局放置。 蓝框位于frameLayout中。 因此,我需要将蓝色框的顶部与绿色框的顶部对齐。 我如何通过使其适用于每个屏幕来做到这一点。 我什至可以做到吗? 感谢名单。 xml看起来像这样。

<FrameLayout>

     <LinearLayout orientation : vertical>

          <TextView/>  // red slab
          <TextView/>  // green slab

</Linearlayout>
<ImagView/> // blue box
</FrameLayout>

题

预期结果

您可以为此使用相对布局,并删除框架布局和线性布局。

<RelativeLayout>


      <TextView/>  // red slab
      <TextView layout_below="1st testview"/>  // green slab

      <ImagView align_top="2nd testview" margin_right="25dp"/> // blue box
</RelativeLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:background="#FA0000" />
    <FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:background="#00FA00" />

    <TextView
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_gravity="right"
        android:layout_marginEnd="10dp"
        android:background="#0006FA" />

</FrameLayout>

</LinearLayout>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM