https://docs.google.com/document/d/1SDDnAG-jkQjC6F85iPgfv3Et1pYl8t03k-TkCN3YcCw/edit如何在嵌套在LinearLayout中的RelativeLayout中实现gravity =“center_vertical”?
我有一个包含股票混合一个Android的首选项页面,以及自定义列表项。自定义列表项目“情绪”和“混合情绪”可以在引用的Google文档中的屏幕截图中看到,并按以下方式运行。 (外部链接是因为没有10的名誉,我不允许发布图像在计算器中...)
1)在用户选择一个值之前,他们只显示他们的标题。 (情绪或混合)
2)用户选择一个值后,他们显示他们的标题和一个自定义工具提示(小彩色正方形),表明他们的选择。
问题:您可以从屏幕截图中看到,在用户选择一个值之前,“心情”文本不居中。我希望它能够居中,然后在做出选择后动态地为自定义工具提示腾出空间。换句话说,我想
<TextView android:id="@+android:id/title"
要到
android:gravity="center_vertical".
这是可能的回应?
我的布局文件看起来像这样。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="60dip"
android:gravity="center_vertical"
android:paddingRight="?android:attr/scrollbarSize">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_marginLeft="15dip"
android:layout_marginRight="6dip">
<TextView android:id="@+android:id/title"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="18sp"/>
<!-- This image represents the dropdown arrow -->
<ImageView
android:gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_toRightOf="@android:id/title"
android:scaleType="fitEnd"
android:src="@drawable/ic_btn_round_more_normal_cropped" />
<monarca_rct.client.customcomponents.MoodScalePresentation
android:id="@+android:id/hpmp_mood_scale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@android:id/title"
android:paddingTop="4.0dp"/>
</RelativeLayout>
</LinearLayout>
谢谢穆拉!您发布的“布局技巧”文章与我想要做的非常相似。不幸的是,阅读完这篇文章后,再试验一下,还包括你的'layout_alignWithParentIfMissing'建议,它仍然没有集中。我很难过... – Colfax