当选择 EditText 时,为什么我的 Android 视图不停留在底部?
我有一个布局,其中有一个按钮栏,其中:
layout_alignParentBottom="true"
我在其顶部有一个 RelativeLayout
,其中包含一个 EditText 和一个 ImageButton。
当我选择 EditText 进行编辑时,com.test.OkCancelBar
会上升到编辑文本的正下方,并且在某些情况下会缩小 EditText 的高度。 EditText 是动态定位的,所以我不确定这是否会影响任何东西。
如何防止 com.test.OkCancelBar 执行此操作,换句话说,强制它始终停留在应用程序的底部?
OkCancelBar.java:mylayout.xml
public OkCancelBar(Context context, AttributeSet attrs)
{
super(context, attrs);
setOrientation(HORIZONTAL);
setGravity(Gravity.CENTER);
setWeightSum(1.0f);
}
:
<com.test.OkCancelBar
android:id="@+id/footerbar_lists"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:paddingTop="0dip"
android:background="@drawable/footer_bkgrnd"/>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="invisible"
android:id="@+id/relative_layout_list_item_edit">
<EditText
android:id="@+id/id_list_edit_text"
android:layout_width="50dip"
android:layout_height="wrap_content"
android:text=""
android:textSize="18sp"
android:editable="true"
android:layout_marginRight="1dip" />
<ImageButton
android:id="@+id/id_btn_save_list"
android:text="Search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/id_list_edit_text"
android:src="@drawable/search">
</ImageButton>
</RelativeLayout>
我还尝试在 OkCancelBar.java 中将重力设置为底部,并在 xml 中显式设置高度:
public OkCancelBar(Context context, AttributeSet attrs)
{
super(context, attrs);
setOrientation(HORIZONTAL);
setGravity(Gravity.BOTTOM);
setWeightSum(1.0f);
<com.test.OkCancelBar
android:id="@+id/footerbar_lists"
android:layout_width="fill_parent"
android:layout_height="55dip"
android:layout_alignParentBottom="true"
android:paddingTop="0dip"
android:gravity="bottom"
android:background="@drawable/footer_bkgrnd"/>
I have a layout where I have a button bar where:
layout_alignParentBottom="true"
I have a RelativeLayout
on top of that which contains an EditText and an ImageButton.
When I select the EditText to edit it, the com.test.OkCancelBar
goes up right below the edit text and in some cases shrinks the height of the EditText. The EditText IS positioned dynamically so I'm not sure if that affects anything.
How can I prevent the com.test.OkCancelBar
from doing this, in other words, force it to stay at the bottom of my app at all times?
OkCancelBar.java:
public OkCancelBar(Context context, AttributeSet attrs)
{
super(context, attrs);
setOrientation(HORIZONTAL);
setGravity(Gravity.CENTER);
setWeightSum(1.0f);
}
mylayout.xml:
<com.test.OkCancelBar
android:id="@+id/footerbar_lists"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:paddingTop="0dip"
android:background="@drawable/footer_bkgrnd"/>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="invisible"
android:id="@+id/relative_layout_list_item_edit">
<EditText
android:id="@+id/id_list_edit_text"
android:layout_width="50dip"
android:layout_height="wrap_content"
android:text=""
android:textSize="18sp"
android:editable="true"
android:layout_marginRight="1dip" />
<ImageButton
android:id="@+id/id_btn_save_list"
android:text="Search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/id_list_edit_text"
android:src="@drawable/search">
</ImageButton>
</RelativeLayout>
I also tried setting gravity to bottom inside OkCancelBar.java and explicitly setting the height in the xml:
public OkCancelBar(Context context, AttributeSet attrs)
{
super(context, attrs);
setOrientation(HORIZONTAL);
setGravity(Gravity.BOTTOM);
setWeightSum(1.0f);
<com.test.OkCancelBar
android:id="@+id/footerbar_lists"
android:layout_width="fill_parent"
android:layout_height="55dip"
android:layout_alignParentBottom="true"
android:paddingTop="0dip"
android:gravity="bottom"
android:background="@drawable/footer_bkgrnd"/>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我可以通过在 AndroidManifest.xml 中为我的活动设置 windowSoftInputMode 来修复它:
I was able to fix it by setting the windowSoftInputMode for my activity in the AndroidManifest.xml :