我需要这样做,绿色图标的基线与此白卡顶部对齐
在我的情况下,我可以将绿色图标的顶部对齐到白卡的顶部。在这种情况下,绿色图标的layout_marginTop不允许将其移动到顶部。
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.wearable.view.CardFrame
android:id="@+id/card_home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TEXT"
android:textColor="@color/black"/>
</android.support.wearable.view.CardFrame>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/menu"
android:layout_alignRight="@id/card_home"
android:layout_alignTop="@id/card_home"
android:layout_marginBottom="30dp"/>
</RelativeLayout>
答案 0 :(得分:1)
你走在正确的轨道上。尝试这样,诀窍是用marginTop替换<ImageView>
中的marginBottom并为其赋值为负值,例如:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/card_home"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#FF00FFFF"
android:layout_centerInParent="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TEXT"
android:textColor="#ff000000"/>
</FrameLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/abc_btn_check_to_on_mtrl_015"
android:layout_alignRight="@id/card_home"
android:layout_alignTop="@id/card_home"
android:layout_marginTop="-15dp"/>
</RelativeLayout>
请注意最后一行:android:layout_marginTop="-15dp"
答案 1 :(得分:1)
您可以尝试使用negativ margin-top
<ImageView
...
android:layout_marginTop="-30dp"
.../>