简体   繁体   English

如何在icon和editText下排很长的行,并在editText的末尾保留一些空间?

[英]How can I have a long line under icon and editText and also leave some space at the end of editText?

I want to have a dialog looked similar to this 我想要一个对话框看起来与此类似

Desired Dialog Look 所需的对话框外观

I tried to code but the design of the dialog looked weird. 我尝试编码,但是对话框的设计看起来很奇怪。

How can I have a long line under icon and editText and also leave some space at the end of editText? 如何在icon和editText下排很长的行,并在editText的末尾保留一些空间?

在此处输入图片说明

xml layout xml布局

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout  xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">


    <ImageView
        android:id="@+id/img"
        android:layout_width="35dp"
        android:layout_height="35dp"
        android:src="@mipmap/add_new_task"
        android:layout_marginLeft="13dp"/>

    <EditText
        android:id="@+id/edtText"
        android:layout_marginLeft="70dp"
        android:layout_width="270dp"
        android:layout_height="wrap_content"
        android:hint="Add a new task"/>

    <ImageView
        android:id="@+id/dateImg"
        android:layout_width="35dp"
        android:layout_height="35dp"
        android:src="@mipmap/imgdate"
        android:layout_below="@+id/edtText"
        android:layout_marginLeft="13dp"/>

    <EditText
        android:id="@+id/date"
        android:layout_marginLeft="70dp"
        android:layout_width="270dp"
        android:layout_height="wrap_content"
        android:layout_below="@+id/edtText"
        android:hint="Date"/>

    <ImageView
        android:id="@+id/timeImg"
        android:layout_width="35dp"
        android:layout_height="35dp"
        android:src="@mipmap/imgtime"
        android:layout_below="@+id/date"
        android:layout_marginLeft="13dp"/>

    <EditText
        android:id="@+id/time"
        android:layout_marginLeft="70dp"
        android:layout_width="270dp"
        android:layout_height="wrap_content"
        android:layout_below="@+id/date"
        android:hint="Time"/>

    <Button
        android:id="@+id/cancelBtn"
        android:background="@color/red"
        android:textColor="@color/white"
        android:text="Cancel"
        android:layout_width="165dp"
        android:layout_height="40dp"
        android:layout_below="@+id/time"
        android:layout_marginLeft="13dp"/>

    <Button
        android:id="@+id/okBtn"
        android:background="@color/light_sky_blue"
        android:textColor="@color/white"
        android:text="Save"
        android:layout_width="165dp"
        android:layout_height="40dp"
        android:layout_below="@+id/time"
        android:layout_marginLeft="190dp"/>


</RelativeLayout>

Code

 @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.action_add_task:
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                LayoutInflater inflater = getLayoutInflater();
                builder.setView(inflater.inflate(R.layout.dialog_with_edittext,null));
                builder.show();
                return true;

            default:
                return super.onOptionsItemSelected(item);
        }
    }

Try this xml i changed the padding on the Relative layout so that it doesnt looks weird from the top/bottom and the sides, also added the lines using the link i provided in my comment ( Vertical line using XML drawable ) and also centered the buttons a little bit since they seemed a little bit off with another relative view inside and removed the underbar of the editTexts 试试这个xml我更改了相对布局上的填充,以便从顶部/底部和侧面看起来不奇怪,还使用我在注释中提供的链接添加了这些行( 使用XML drawable的垂直线 ),并且将按钮居中一点点,因为它们似乎在内部带有另一个相对视图时有点偏离,并删除了editTexts的下栏

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout  xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:paddingTop="8dp"
    android:paddingBottom="5dp"
    android:paddingLeft="5dp"
    android:paddingRight="5dp"
    android:layout_height="wrap_content">


    <ImageView
        android:id="@+id/img"
        android:layout_width="35dp"
        android:layout_height="35dp"
        android:background="#000"
        android:layout_marginLeft="13dp"/>

    <EditText
        android:layout_marginTop="11dp"
        android:layout_marginBottom="11dp"
        android:layout_marginLeft="20dp"
        android:layout_toRightOf="@id/img"
        android:background="@android:color/transparent"
        android:id="@+id/edtText"
        android:layout_width="270dp"
        android:layout_height="wrap_content"
        android:hint="Add a new task"/>
    <View
        android:layout_below="@id/edtText"
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:background="#000"
        android:layout_marginTop="-4dp"/>
    <ImageView
        android:id="@+id/dateImg"
        android:layout_width="35dp"
        android:layout_height="35dp"
        android:background="#000"
        android:layout_below="@+id/edtText"
        android:layout_marginLeft="13dp"/>

    <EditText
        android:layout_marginTop="11dp"
        android:layout_marginBottom="11dp"
        android:layout_marginLeft="20dp"
        android:layout_toRightOf="@id/dateImg"
        android:background="@android:color/transparent"
        android:id="@+id/date"
        android:layout_width="270dp"
        android:layout_height="wrap_content"
        android:layout_below="@+id/edtText"
        android:hint="Date"/>
    <View
        android:layout_below="@id/date"
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:background="#000"
        android:layout_marginTop="-4dp"/>

    <ImageView
        android:id="@+id/timeImg"
        android:layout_width="35dp"
        android:layout_height="35dp"
        android:background="#000"
        android:layout_below="@+id/date"
        android:layout_marginLeft="13dp"/>

    <EditText
        android:layout_marginTop="11dp"
        android:layout_marginBottom="11dp"
        android:layout_marginLeft="20dp"
        android:layout_toRightOf="@id/timeImg"
        android:background="@android:color/transparent"
        android:id="@+id/time"
        android:layout_width="270dp"
        android:layout_height="wrap_content"
        android:layout_below="@+id/date"
        android:hint="Time"/>

    <View
        android:layout_below="@id/time"
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:background="#000"
        android:layout_marginTop="-4dp"/>

<RelativeLayout
    android:layout_centerHorizontal="true"
    android:layout_below="@+id/time"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <Button
        android:layout_marginTop="5dp"
        android:id="@+id/cancelBtn"
        android:background="#fc2a2a"
        android:textColor="#ffffff"
        android:text="Cancel"
        android:layout_width="165dp"
        android:layout_height="40dp"
        android:layout_marginLeft="15dp"
        android:layout_alignParentLeft="true"/>

    <Button
        android:layout_marginTop="5dp"
        android:id="@+id/okBtn"
        android:background="#64e3ff"
        android:textColor="#fff"
        android:text="Save"
        android:layout_width="165dp"
        android:layout_height="40dp"
        android:layout_marginRight="15dp"
        android:layout_alignParentRight="true"/>
</RelativeLayout>

</RelativeLayout>

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM