如何将EditText拉伸到整个手机的宽度并为1个按钮留出空间?

时间:2014-12-09 01:15:32

标签: android xml android-actionbar

我正在尝试将EditText(在ActionBar上)拉伸到“几乎”整个屏幕的宽度。首先应该为右侧的按钮留出空间,然后其余部分是EditText的速度。我可以放大约300dp,这可能会让我的手机看起来不错,但这不是一个更好的解决方案。

我的代码: action_menu

     

<item
    android:id="@+id/action_settings"
    android:actionLayout="@layout/action_item_edit_text"
    android:showAsAction="always"
    android:title="Search"/>
<item
    android:id="@+id/add"
    android:icon="@drawable/add"
    android:showAsAction="always"
    android:title="Add"/>

<!-- Settings, should always be in the overflow -->

action_item_edit_text

<EditText xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/editInput"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:hint="Write something"
android:padding="6dp"
android:singleLine="true"
android:textColor="@android:color/black"
android:textColorHint="#BBBBBB"
android:textSize="14sp" />    

1 个答案:

答案 0 :(得分:0)

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <Button 
        android:id="@+id/button"
        android:layout_alignParentRight="true"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content" />

    <EditText
        android:layout_toLeftOf="@id/button"
        android:layout_alignParentLeft="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</RelativeLayout>

这样的事情。我没有测试过这个,我只是盲目地写了,但这个概念是合理的。