2013-03-13 80 views
1

美好的一天(或傍晚或夜晚) 我正在開發針對android的應用程序,我對一件事情非常好奇。我有一個活動,用戶與另一個用戶聊天,比如「即時通訊」聊天。底部有一個EditText,頂部有一個ActionBar。我需要的是,當用戶輸入消息並且屏幕上顯示軟件鍵盤時,我的活動應該向上移動,但操作欄仍然應該「粘」到屏幕的頂部,因爲它有一些有價值的控件。 同樣,這不是一個ActionBar,而是一個父級垂直線性佈局中的48dp高度佈局。所以我需要知道是否有一種簡單的方法可以防止佈局移出屏幕時移動到頂端。 我試圖把一切都放在一個FrameLayout裏和放在它上面這個酒吧,但鍵盤上的AndroidManifest打開它熄滅屏幕太...狀態欄始終顯示在屏幕上

回答

0

在你的活動,你應該把這樣的:機器人:windowSoftInputMode =」 adjustResize」

0

使用這樣的事情:

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <com.myapp.MyActionBar 
     android:layout_width="match_parent" 
     android:layout_height="48dp"/> 

    <LinearLayout 
     android:id="@+id/mylayout" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1dp"/> 

    <!-- Add your edittext and button --> 

</LinearLayout> 

這將確保在動作條和的EditText +按鈕是百達在屏幕上,而mylayout佔據了屏幕的其餘部分。顯示鍵盤時,mylayout會縮小。

0

嘗試爲清單中的活動添加android:windowSoftInputMode =「adjustResize」。這告訴Android在鍵盤出現時完全調整您的佈局,而不是平移它。請注意,如果整個佈局沒有足夠的空間,這仍然無法工作。但是如果你的頂層佈局是一個RelativeLayout,你應該能夠使它工作,編輯文本設置爲對齊底部,頂部欄對齊頂部,中間部分爲fill_parent並且位於編輯文本的上方,酒吧。

0

使用的RelativeLayout爲您的基地佈局,並添加機器人:layout_alignParentTop =「true」以你的動作條,以保持它

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

    <LinearLayout 
     android:id="@+id/action_bar_layout" 
     android:layout_width="match_parent" 
     android:layout_height="48dp" 
     android:layout_alignParentTop="true" > 
    </LinearLayout> 

    <TextView 
     android:id="@+id/text_view" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" /> 

</RelativeLayout>