0
我有一個DialogFragment
具有以下佈局:使佈局總是可見的一部分時,會顯示鍵盤
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/rounded_rect_light">
<RelativeLayout
android:id="@+id/create_note_top_panel"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#f2f3f5">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="Cancel"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title"
android:gravity="center"
android:layout_centerInParent="true"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:text="Send"/>
</RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/quote_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_alignParentTop="true"
android:src="@drawable/edu4_create_note_quotes"/>
<TextView
android:id="@+id/quote_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/quote_image"
android:scrollbars="vertical"
android:fadeScrollbars="false"
android:text="The issue is that soft keyboard is very tricky and this\n quesakdf\njk\nlsd\nfj\nklsdjfklsdjfkl jsdklfj skldjkljfklsdjklfjsdklfjsdkljfkls"
android:maxLines="5"/>
<EditText
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_below="@id/quote_text"
android:layout_margin="10dp"
android:gravity="top|left"
android:background="@drawable/rounded_rect_background_white"
android:padding="5dp"/>
</RelativeLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="15dp"
android:layout_marginLeft="10dp">
<TextView
android:id="@+id/visibleTo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_gravity="center_vertical"
android:text="Publish"/>
<ToggleButton
android:id="@+id/switchPublishToCourse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"/>
</LinearLayout>
我想的是,鍵盤打開時,頂部面板(android:id="@+id/create_note_top_panel"
)會在頂部可見,並且對話框(它的背景)將位於鍵盤上方,底部的TextView
和ToggleButton
將可見,其餘佈局將可滾動。
這也許SO答案將滿足您的需求。如何在Android中捕獲'虛擬鍵盤顯示/隱藏'事件? http://stackoverflow.com/a/7423586/1027550 – MRodrigues 2015-03-03 12:29:56
謝謝,但我不明白這是如何幫助我太多 – piojo 2015-03-03 13:42:26
我以爲你聽到鍵盤被打開的事件有困難。 – MRodrigues 2015-03-03 14:02:36