我试图创建一个弹出窗口,您可以在其中阅读和撰写评论(例如在Facebook应用上)。它工作得很好但是当我选择编辑文本时,软键盘会隐藏编辑文本,所以我看不出我写的是什么。我尝试了我在大多数类似主题中找到的解决方案,我在我的活动中添加了这一行在清单中:
android:windowSoftInputMode="stateVisible|adjustResize"/>
但它没有用。
这是我的一些代码:
private PopupWindow popWindow;
public void onShowPopup(View v){
LayoutInflater layoutInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// inflate the custom popup layout
final View inflatedView = layoutInflater.inflate(R.layout.comments_popup_layout,null);
// find the ListView in the popup layout
ListView listView = (ListView)inflatedView.findViewById(R.id.commentsListView);
// get device size
Display display = getWindowManager().getDefaultDisplay();
final Point size = new Point();
display.getSize(size);
// fill the data to the list items
setSimpleList(listView);
// set height depends on the device size
popWindow = new PopupWindow(inflatedView, size.x - 200,size.y - 500, true );
popWindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.comments_bg));
// make it focusable to show the keyboard to enter in `EditText`
popWindow.setFocusable(true);
// make it outside touchable to dismiss the popup window
popWindow.setOutsideTouchable(true);
// show the popup at bottom of the screen and set some margin at bottom ie,
popWindow.showAtLocation(v, Gravity.BOTTOM, 0,100);
}
void setSimpleList(ListView listView){
ArrayList<String> contactsList = new ArrayList<String>();
for (int index = 0; index < 10; index++) {
contactsList.add("I am @ index " + index + " today " + Calendar.getInstance().getTime().toString());
}
listView.setAdapter(new ArrayAdapter<String>(ListEddystoneActivity.this,
R.layout.comments_list_item, android.R.id.text1,contactsList));
}
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:id="@+id/headerLayout"
android:layout_width="match_parent"
android:layout_height="30dp"
android:orientation="horizontal"
android:layout_alignParentTop="true"
android:gravity="center">
<TextView
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some One and 20 Others Like this"
android:textColor="@color/black"
android:textStyle="bold"
android:layout_margin="5dp"/>
</LinearLayout>
<ListView
android:id="@+id/commentsListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:layout_below="@id/headerLayout"
android:paddingBottom="50dp"
android:layout_marginBottom="0dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:id="@+id/writeCommentView">
<EditText
android:id="@+id/writeComment"
android:hint="Write a Comment"
android:layout_width="match_parent"
android:layout_height="50dp"
android:textSize="12dp"
android:textColor="@color/black"
android:background="#00000000"/>
</LinearLayout>
</RelativeLayout>
</ScrollView>
谢谢:)
答案 0 :(得分:0)
ScrollView应该只对孩子很有可能是linearLayout。
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/headerLayout"
android:layout_width="match_parent"
android:layout_height="30dp"
android:orientation="horizontal"
android:layout_alignParentTop="true"
android:gravity="center">
<TextView
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some One and 20 Others Like this"
android:textColor="@color/black"
android:textStyle="bold"
android:layout_margin="5dp"/>
</LinearLayout>
<ListView
android:id="@+id/commentsListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:layout_below="@id/headerLayout"
android:paddingBottom="50dp"
android:layout_marginBottom="0dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:id="@+id/writeCommentView">
<EditText
android:id="@+id/writeComment"
android:hint="Write a Comment"
android:layout_width="match_parent"
android:layout_height="50dp"
android:textSize="12dp"
android:textColor="@color/black"
android:background="#00000000"/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</ScrollView>