正常布局 - 适应layout_toRightOf 4"和4,7"屏幕

时间:2017-09-09 08:59:04

标签: android android-layout

我有以下示例:一个edittext,右边是一个图像按钮。我现在唯一的解决方案是设计4"屏幕。

所以看看4"屏幕是这样的:

enter image description here

和4,7"屏幕:

enter image description here

是否有解决方案将edittext的宽度绘制到右边,仍然可以看到图像按钮?我尝试过使用width = wrap_content或match_parent + marginRight,但我无法到达任何地方:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">


    <EditText
        android:id="@+id/edtl"
        android:layout_width="280dp"
        android:layout_height="wrap_content"
        android:hint="Test enter text to modify"
        android:textSize="@dimen/a_normal"
        android:textColor="#0000ff"
        android:inputType="textWebEditText"
        android:paddingLeft="10dp"
        android:layout_marginTop="20dp"
        android:layout_alignStart="@id/sel_email"
        />

    <ImageButton
        android:id="@+id/info"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/edtl"
        android:layout_alignBottom="@id/edtl"
        android:src="@mipmap/info"
        />
</RelativeLayout>

我试过了:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">


    <EditText
        android:id="@+id/edtl"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Test enter text to modify text1 text2 text3 text4"
        android:textSize="@dimen/a_normal"
        android:textColor="#0000ff"
        android:inputType="textWebEditText"
        android:paddingLeft="10dp"
        android:layout_marginTop="20dp"
        />

    <ImageButton
        android:id="@+id/info"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignRight="@id/edtl"
        android:layout_alignEnd="@id/edtl"
        android:layout_alignBottom="@id/edtl"
        android:src="@mipmap/info"
        />
</RelativeLayout>

看起来像那样。 close:我错过了edittext和imagebutton之间的差距。

enter image description here

2 个答案:

答案 0 :(得分:2)

使用此功能,尝试并正常工作 -

    <ImageButton
        android:id="@+id/info"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@id/edtl"
        android:layout_alignParentRight="true"
        />
    <EditText
        android:id="@+id/edtl"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Test enter text to modify"
        android:textColor="#0000ff"
        android:inputType="textWebEditText"
        android:paddingLeft="10dp"
        android:layout_marginTop="20dp"
        android:layout_toLeftOf="@id/info"
        />

答案 1 :(得分:1)

请试试这个:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <EditText
        android:id="@+id/edtl"
        android:layout_width="match_parent"        
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@id/info"
        android:hint="Test enter text to modify"
        android:textSize="@dimen/a_normal"
        android:textColor="#0000ff"
        android:inputType="textWebEditText"
        android:paddingLeft="10dp"
        android:layout_marginTop="20dp"/>

    <ImageButton
        android:id="@+id/info"
        android:margin_left="20dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:alignParentRight="true"
        android:alignParentEnd="true"       
        android:src="@mipmap/info"
        />

</RelativeLayout>

这将使EditText保持在ImageButton左侧并占据宽度的其余部分。

相关问题