【发布时间】:2016-04-08 21:25:44
【问题描述】:
我是安卓新手。我正在尝试在 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>
提前致谢。
【问题讨论】:
-
尝试将父布局(主要是线性布局)添加到 ScrollView 并将 ID(@+id/popup_element) 分配给该父布局,而不是将 ID 分配给 ScrollView。并确保您的 ScrollView 仅包含一个子布局。因此,将您的其他布局合并到单个 LinearLayout 中,并将该布局作为 ScrollView 的子级!
标签: android xml android-studio scrollview