【发布时间】:2015-08-03 18:57:36
【问题描述】:
您好,我的应用中有一个surfaceview。我所有的游戏都是这样构建的:
实例化实现 SurfaceHolder.Callback 接口的 Surfaceview 的子类。
现在我想在单击按钮时打开一个菜单(自定义对象) 这应该会显示一个带有可滚动文本视图的片段(我认为只是一个带有一个文本视图元素的列表视图,因为我认为如果文本很长,单独的文本视图是不可滚动的。欢迎任何相反的论点)
但是我该怎么做呢?
我已经有了一个 Fragment 类和一个片段布局
编辑 3:
好的,我已经设法像这样以编程方式设置 SurfaceView:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(savedInstanceState==null)
{
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
prefs=getSharedPreferences("myPrefs",0);
mView=new MainView(this);
loadSharedPrefs();
LinearLayout myLayout = (LinearLayout)findViewById(R.id.main);
mView.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT));
myLayout.addView(mView);
}
}
布局只是一个空白的线性布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:id="@+id/main">
</LinearLayout>
所以现在我只需要在单击按钮时显示一个片段
到目前为止的片段类:
public class HintListFragment extends Fragment
{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.hintlist, container, false);
}
}
以及该片段的布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/hintList"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="sagdjsahgdhascxasbcxahsgdhsagdhasgdashgdsajsgdh"
/>
</LinearLayout>
【问题讨论】:
标签: android android-layout android-fragments surfaceview