我是android的新手。我正在尝试在android上实现可滚动的弹出窗口。
如果我进行滚动视图在我的视图中显示错误 ScrollView只能托管一个直接子项(详情)
这是我的代码
private PopupWindow pwindo;
private void initiatePopupWindow() {
try {
// We need to get the instance of the LayoutInflater
LayoutInflater inflater = (LayoutInflater) About.this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.screen_popup,
(ViewGroup) findViewById(R.id.popup_element));
pwindo = new PopupWindow(layout,700,1000, true);
// pwindo.showAtLocation(layout, Gravity.CENTER, 0, 0);
// pwindo.showAsDropDown(layout, 80, 80);
btnClosePopup = (Button) layout.findViewById(R.id.btn_close_popup);
btnClosePopup.setOnClickListener(cancel_button_click_listener);
} catch (Exception e) {
e.printStackTrace();
}
}
private OnClickListener cancel_button_click_listener = new OnClickListener() {
public void onClick(View v) {
pwindo.dismiss();
}
};
我的观点
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="@+id/popup_element">
<TextView/>
<TextView/>
<TextView/>
<ImageButton/>
<ImageButton/>
.
.
.
.
</ScrollView>
提前致谢。
答案 0 :(得分:1)
将线性布局作为父级:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="@+id/popup_element">
<TextView/> <TextView/> <TextView/> <ImageButton/> <ImageButton/> . . . .
</ScrollView>
</linearLayout>
答案 1 :(得分:1)
下面你应该这样做!
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="@+id/popup_element">
<TextView/>
<TextView/>
<TextView/>
<ImageButton/>
<ImageButton/>
.
.
.
.
</ScrollView>
</LinearLayout>
答案 2 :(得分:1)
将LinearLayout放在ScrollView中作为you should place one child in it containing the entire contents to scroll; this child may itself be a layout manager with a complex hierarchy of objects
布局应如下所示
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/popup_element">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView/>
<TextView/>
<TextView/>
<ImageButton/>
<ImageButton/>
</LinearLayout>
</ScrollView>
将所有这些观点放在LinearLayout
中
并为弹出窗口提供更少的宽度和高度
pwindo = new PopupWindow(layout,400,400, true);
答案 3 :(得分:1)
这可能对你有所帮助......
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/popup_element">>
<LinearLayout
android:id="@+id/child">
<TextView/>
<TextView/>
<TextView/>
<ImageButton/>
<ImageButton/>
.
.
.
.
</LinearLayout>
</ScrollView>
将LinearLayout添加为直接子项并将其他控件放入其中。
答案 4 :(得分:0)
ScrollView
正在PopupWindow
上工作!
我的问题是由于弹出窗口的高度不受限制的事实
您可以通过View.measure(int widthMeasureSpec, int heightMeasureSpec)
方法预先确定版式的高度,但是它不应是无限的,并且高度小于屏幕或窗口的大小,然后会滚动