Android 未使用“对齐底部”
我的布局使用了Android 未使用“对齐底部”,android,android-relativelayout,Android,Android Relativelayout,我的布局使用了线性布局而不是相对布局。我想将无边框按钮添加到布局中,如下所示: 因此,要使用它,我必须将我的LinearLayouts更改为RelativeLayouts。这在很大程度上起到了很好的作用。但是,当我尝试将alignParentBottom用于其中一个RelativeLayouts时,它不起作用-它只是与我的另一个按钮重叠 这是我的xml: <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:andr
线性布局
而不是相对布局
。我想将无边框按钮添加到布局中,如下所示:
因此,要使用它,我必须将我的LinearLayouts
更改为RelativeLayouts
。这在很大程度上起到了很好的作用。但是,当我尝试将alignParentBottom用于其中一个RelativeLayouts时,它不起作用-它只是与我的另一个按钮重叠
这是我的xml:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".xxx" >
<com.xxx.xxx.customedittext
android:id="@+id/qn_et_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:drawableRight="@drawable/delete"
android:hint="@string/qn_et_title_hint"
android:inputType="textCapSentences|textMultiLine"
android:paddingTop="5dp" />
<com.xxx.xxx.customedittext
android:id="@+id/qn_et_body"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/qn_et_title"
android:drawableRight="@drawable/delete"
android:hint="@string/qn_et_body_hint"
android:inputType="textCapSentences|textMultiLine" />
<CheckBox
android:id="@+id/qn_cb_ongoing"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/qn_et_body"
android:text="@string/qn_cb_ongoing" />
<Button
android:id="@+id/qn_b_create"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/qn_cb_ongoing"
android:text="@string/qn_b_create" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_alignParentBottom="true" >
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:layout_alignParentTop="true"
android:layout_marginLeft="4dip"
android:layout_marginRight="4dip"
android:background="?android:attr/dividerVertical" />
<View
android:id="@+id/ViewColorPickerHelper"
android:layout_width="1dip"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="4dip"
android:layout_marginTop="4dip"
android:background="?android:attr/dividerVertical" />
<Button
android:id="@+id/BtnColorPickerCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@id/ViewColorPickerHelper"
android:background="?android:attr/selectableItemBackground"
android:text="@android:string/cancel" />
<Button
android:id="@+id/BtnColorPickerOk"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_toRightOf="@id/ViewColorPickerHelper"
android:background="?android:attr/selectableItemBackground"
android:text="@android:string/ok" />
</RelativeLayout>
</RelativeLayout>
</ScrollView>
在
滚动视图上使用以下属性:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="3dp"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".QuickNoteFragment" >
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="false" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="@+id/qn_et_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/qn_et_title_hint"
android:inputType="textCapSentences|textMultiLine"
android:paddingTop="5dp" />
<EditText
android:id="@+id/qn_et_body"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/qn_et_title"
android:hint="@string/qn_et_body_hint"
android:inputType="textCapSentences|textMultiLine"
android:paddingTop="10dp" />
<CheckBox
android:id="@+id/qn_cb_ongoing"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/qn_et_body"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="@string/qn_cb_ongoing" />
</RelativeLayout>
</ScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_alignParentBottom="true" >
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:layout_alignParentTop="true"
android:layout_marginLeft="4dip"
android:layout_marginRight="4dip"
android:background="?android:attr/dividerVertical" />
<View
android:id="@+id/ViewColorPickerHelper"
android:layout_width="1dip"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="4dip"
android:layout_marginTop="4dip"
android:background="?android:attr/dividerVertical" />
<Button
android:id="@+id/qn_b_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@id/ViewColorPickerHelper"
android:background="?android:attr/selectableItemBackground"
android:text="@android:string/cancel" />
<Button
android:id="@+id/qn_b_create"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_toRightOf="@id/ViewColorPickerHelper"
android:background="?android:attr/selectableItemBackground"
android:text="@string/qn_b_create" />
</RelativeLayout>
</RelativeLayout>
<RelativeLayout android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/bottom"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_alignParentBottom="true">
<!-- rest of the code -->
</RelativeLayout>
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@id/bottom"
android:layout_alignParentTop="true" >
<!-- rest of the code -->
</ScrollView>
<RelativeLayout>
在滚动视图上使用以下属性:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="3dp"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".QuickNoteFragment" >
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="false" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="@+id/qn_et_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/qn_et_title_hint"
android:inputType="textCapSentences|textMultiLine"
android:paddingTop="5dp" />
<EditText
android:id="@+id/qn_et_body"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/qn_et_title"
android:hint="@string/qn_et_body_hint"
android:inputType="textCapSentences|textMultiLine"
android:paddingTop="10dp" />
<CheckBox
android:id="@+id/qn_cb_ongoing"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/qn_et_body"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="@string/qn_cb_ongoing" />
</RelativeLayout>
</ScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_alignParentBottom="true" >
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:layout_alignParentTop="true"
android:layout_marginLeft="4dip"
android:layout_marginRight="4dip"
android:background="?android:attr/dividerVertical" />
<View
android:id="@+id/ViewColorPickerHelper"
android:layout_width="1dip"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="4dip"
android:layout_marginTop="4dip"
android:background="?android:attr/dividerVertical" />
<Button
android:id="@+id/qn_b_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@id/ViewColorPickerHelper"
android:background="?android:attr/selectableItemBackground"
android:text="@android:string/cancel" />
<Button
android:id="@+id/qn_b_create"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_toRightOf="@id/ViewColorPickerHelper"
android:background="?android:attr/selectableItemBackground"
android:text="@string/qn_b_create" />
</RelativeLayout>
</RelativeLayout>
<RelativeLayout android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/bottom"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_alignParentBottom="true">
<!-- rest of the code -->
</RelativeLayout>
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@id/bottom"
android:layout_alignParentTop="true" >
<!-- rest of the code -->
</ScrollView>
<RelativeLayout>
这种行为很正常。根RelativeLayout位于qn_b_create
按钮的右下方,因此将最后一个RelativeLayout
与底部对齐将使它们重叠。尝试使用ScrollView
上的android:fillViewport=“true”
来填充屏幕。此外,在ScrollView
中只显示内容部分,而不显示底部按钮是有意义的,否则当内容较大时,这些按钮将从屏幕上消失(我认为您不需要)。@Luksprog谢谢!非常有效nicely@Luksprog当我这样做时,ScrollView与底部对齐的RelativeLayout重叠。检查您使用的规则。作为根用户,您将拥有一个RelativeLayout(其中是当前的ScrollView
)。然后高度为48dp的RelativeLayout将与父对象的底部对齐(将其放在xml定义的第一位)。然后,包含内容的滚动视图将具有规则:layout_alignParentTop和layout_位于上一个RelativeLayout(具有48 dp的那一个)之上。@Luksprog抱歉,我不完全理解。我在问题中添加了更新的代码,说明行为是正常的。根RelativeLayout位于qn_b_create
按钮的右下方,因此将最后一个RelativeLayout
与底部对齐将使它们重叠。尝试使用ScrollView
上的android:fillViewport=“true”
来填充屏幕。此外,在ScrollView
中只显示内容部分,而不显示底部按钮是有意义的,否则当内容较大时,这些按钮将从屏幕上消失(我认为您不需要)。@Luksprog谢谢!非常有效nicely@Luksprog当我这样做时,ScrollView与底部对齐的RelativeLayout重叠。检查您使用的规则。作为根用户,您将拥有一个RelativeLayout(其中是当前的ScrollView
)。然后高度为48dp的RelativeLayout将与父对象的底部对齐(将其放在xml定义的第一位)。然后,包含内容的滚动视图将具有规则:layout_alignParentTop和layout_位于上一个RelativeLayout(具有48 dp的那一个)之上。@Luksprog抱歉,我不完全理解。我在问题中添加了更多的最新代码,谢谢!完全解决了这个问题。还要感谢@Luksprog在评论中第一次帮助我:-)谢谢!完全解决了这个问题。还要感谢@Luksprog首先帮助我发表评论:——)