2016-09-24 19 views
1

我想有一個對話框看起來類似於此如何在圖標和editText下留出長長的一行,並在editText的末尾留出一些空格?

Desired Dialog Look

我試圖代碼,但該對話框的設計顯得怪異。

如何在圖標和editText下劃一條長條線,並在editText的末尾留下一些 空間?

enter image description here

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> 

代碼

@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); 
     } 
    } 
+0

繪製線條像這樣的東西: http://stackoverflow.com/questions/2658772/vertical-line-using-xml-drawable 至於空間只需添加一些填充到EditTexts – ivan

回答

2

試試這個XML我改變填充上相對佈局,使得它不看起來與怪異該頂部/底部和兩側,還添加了我在評論(Vertical line using 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> 

enter image description here

+0

感謝您的答案和所有有用的提示。我嘗試使用'android:background =「@ android:color/transparent」'刪除editText的underbar行,所有的佈局運行 –

+0

Ohh對不起,沒有注意到生病立即嘗試實現它(/ oo)/ – ivan

+0

完成後,如果您需要任何其他編輯生病,很高興知道它。 – ivan

相關問題