2015-01-09 101 views
1

我的佈局有問題。在我的佈局中,我有一個EditText,一個DatePicker,一個TimePicker和一個Button。點擊EditText打開導致圖片中顯示的問題的鍵盤。 「android:windowSoftInputMode」中的不同方法不會改變任何內容。現在我不知道如何解決這個問題。打開鍵盤破壞佈局

在輸入文本之前隱藏其他組件是否是個好主意?這裏預期的行爲是什麼?

correct layout

crumbled layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" 
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
android:paddingBottom="@dimen/activity_vertical_margin" 
tools:context="patrickengelkes.com.alleneune.activities.CreateEventActivity"> 


<EditText 
    android:id="@+id/event_name_edit_text" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" /> 

<DatePicker 
    android:id="@+id/event_date_picker" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/event_name_edit_text" 
    android:layout_centerHorizontal="true" /> 

<Button 
    android:id="@+id/send_event_invites" 
    android:text="@string/send_event_invites_to_members" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentEnd="true" /> 

<TimePicker 
    android:id="@+id/event_time_picker" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/send_event_invites" 
    android:layout_alignLeft="@+id/event_time_picker" 
    android:layout_alignStart="@+id/event_time_picker" /> 

提前感謝!

+0

您可以在未打開鍵盤的情況下添加布局圖片嗎?或者更確切地說它應該是什麼樣子的圖片? – bwegs 2015-01-09 22:14:50

+0

'不同的方法來自「android:windowSoftInputMode」'你究竟做了什麼?你的'活動'的'主題'是什麼? – Mike 2015-01-09 22:15:17

+0

我嘗試過「adjustPan」,「stateHidden」,「stateAlwaysHidden」和「adjust resize」。似乎沒有任何改變。在我的文章中添加了正確佈局的圖片。 – Deutro 2015-01-09 22:26:37

回答

1

我認爲下面的問題是:

你告訴你的DatePicker,它應該是被固定在頂部的EditText下方!

然後,您告訴您的TimerPicker高於您的底部固定的Button

現在,當您打開SoftInput時,按鈕向上移動,您的TimePicker也會移動。但是EditText保持固定在頂部,您的DatePicker也是如此。

兩個TimePickerDatePickerwrap_content所以唯一的出路就是TimePickerDatePicker!這正是它的樣子!

我會試着告訴TimePicker,我應該保持低於DatePicker

android:below=="@id/event_date_picker" 

,看看會發生什麼!因爲在這種情況下,它被迫停留在DatePicker以下,並且不再像浮動在DatePicker中那樣的一層!我沒有嘗試,也許你需要正確聲明android:windowSoftInputMode。因爲我不確定它現在是如何宣佈的! 希望它有幫助!

+0

是的,這工作。不幸的是,日期選擇器仍然在EditText下方。正如你在第一張照片中看到的那樣,1月份並不完全可見。 – Deutro 2015-01-10 15:07:38

+0

@deutro很樂意幫助你。第一個看起來不錯,我認爲你的意思是第二個 – Mike 2015-01-10 15:19:28

+0

對不起。我的意思是第二張照片。 – Deutro 2015-01-10 15:43:44