我正在尝试旋转ListView
custom 的内部popupWindow
。以下是我的设置:
这是弹出 XML board_dialog.xml
,:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/boardll"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<ListView
android:id="@+id/boardoptions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="@array/options_array_board" />
</RelativeLayout>
我的自定义BoardPopup
类:
public class BoardPopup extends PopupWindow {
private static final String TAG = BoardPopup.class.getSimpleName();
Context context;
RelativeLayout ll;
ListView lv;
private OnSubmitListener mListener;
public BoardPopup (Context ctx, OnSubmitListener listener) {
super(ctx);
context = ctx;
mListener = listener;
setContentView(LayoutInflater.from(context).inflate(R.layout.board_dialog, null));
setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
View popupView = getContentView();
setFocusable(true);
lv = (ListView) popupView.findViewById(R.id.boardoptions);
ll = (RelativeLayout) popupView.findViewById(R.id.boardll);
}
public void show(View v) {
showAtLocation(v, Gravity.CENTER, 0, 0);
}
public interface OnSubmitListener {
void valueChanged(String name, String number);
}
public void fixDimensions() {
getContentView().setBackgroundColor(Color.RED); //to highlight views
ll.setRotation(90);
update(292,630); //These numbers are not meant to be constant
}
}
在我的活动中,显示弹出窗口,我必须覆盖onWindowFocusChanged
以获得弹出窗口内视图的绘制后尺寸:
popup = new BoardPopup(c, MainGamePanel.this);
popupJustCreated = true;
popup.show(v);
.
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (popup!=null && popupJustCreated) {
popup.fixDimensions();
popupJustCreated = false;
}
}
如果我注释掉ll.setRotation(90);
然后一切看起来update(292,630);
都fixDimensions()
很正常:
如果我添加ll.setRotation(90);
:
最后,如果我添加update(292,630);
:
在最终图像中,为什么布局没有填充弹出窗口?那个灰色区域是什么视图?我怎样才能让它正常旋转和调整大小?
我尝试过的其他一些事情没有成功:
- 使用
LinearLayout
代替RelativeLayout
wrap_content
和的所有不同组合match_parent
- 对自定义做基本相同的事情
DialogFragment