多窗格中的 "Gridview Images" 和 "Full screen" 片段 (android)
"Gridview Images" and "Full screen" fragments in multi pane(android)
我是新来的android..我的英语一点:(
我想开发多窗格应用程序。
两个片段 "Gridview" 和 "Full screen"
我知道多窗格,但我不知道多窗格中的 Gridview 和全屏。
因为 ListView 的所有示例。
请帮助我
这个应用程序很适合我,但太复杂了=
http://www.codeproject.com/Articles/779293/Building-Dynamic-UI-for-Android-Devices
如果我正确理解你的问题,这是一个简单的实现
------------ 创建 GridView ------------
- 对于 GridView,您需要一个用于 GridView 对象的适配器和用于列的图像,例如使用国家/地区列表和国旗图像,
在 res 中创建可绘制文件夹并在可绘制文件夹中添加国旗图像
在 res/layout
中创建 gridlayout.xml
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/border"
android:padding="5dp">
<ImageView
android:id="@+id/gridimage"
android:layout_height="65dp"
android:layout_width="65dp"
android:src="@drawable/icon"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true">
</ImageView>
<TextView
android:id="@+id/gridtext"
android:text="TextView"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="@+id/imageView1"
android:layout_marginTop="2dp"
android:layout_centerHorizontal="true"
android:textSize="18sp"
android:ellipsize="marquee"></TextView>
</RelativeLayout>
在 res/Layout 文件夹中创建 gridrow.xml
<GridView
android:id="@+id/gridView1"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:numColumns="auto_fit"
android:horizontalSpacing="10dp"
android:verticalSpacing="10dp">
</GridView>
创建GridAdapter.javaclass
public class GridAdapter extends BaseAdapter {
private ArrayList<String> CountryList;
private ArrayList<Integer> CountryFlag;
private Activity activity;
public GridAdapter(Activity activity,ArrayList<String> CountryList, ArrayList<Integer> CountryFlag){
super();this.CountryList = CountryList;
this.CountryFlag = CountryFlag;
this.activity = activity;}
@Override
public int getCount() {
return CountryList.size();
}
@Override
public String getItem(int position) {
return CountryList.get(position);
}
@Override
public long getItemId(int position) {
return 0;
}
public static class ViewHolder
{
public ImageView imgViewFlag;
public TextView txtViewTitle;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder view;
LayoutInflater inflator = activity.getLayoutInflater();
if(convertView==null)
{
view = new ViewHolder();
convertView = inflator.inflate(R.layout.gridview_row, null);
view.txtViewTitle = (TextView) convertView.findViewById(R.id.gridtext);
view.imgViewFlag = (ImageView) convertView.findViewById(R.id.gridimage);
convertView.setTag(view);
}
else
{
view = (ViewHolder) convertView.getTag();
}
view.txtViewTitle.setText(CountryList.get(position));
view.imgViewFlag.setImageResource(CountryFlag.get(position));
return convertView;
}
}
- 创建片段 GridViewActivty
public class GridViewActivty 扩展 Fragment {
private ArrayList CountryList = new ArrayList();
private ArrayList CountryFlag = new ArrayList();
私有 GridView mygrid;
私有 GridAdapter 适配器;
私有上下文上下文;
public GridViewActivty(){}
@覆盖
public 查看 onCreateView(LayoutInflater inflater,
ViewGroup 容器,Bundle savedInstanceState)
{ 查看 rootView = inflater.inflate(R.layout.gridlayout.xml, container, false);</p>
<pre><code> CountryList = new ArrayList<String>();
CountryList.add("South Africa");
CountryList.add("Spain");
CountryList.add("Canada");
CountryList.add("China");
CountryList.add("France");
CountryList.add("Germany");
CountryList.add("Iran");
CountryList.add("Italy");
CountryList.add("Japan");
CountryList.add("Korea");
CountryList.add("Mexico");
CountryList.add("Netherlands");
CountryFlag = new ArrayList<Integer>();
CountryFlag.add(R.drawable.southafrica);
CountryFlag.add(R.drawable.spain);
CountryFlag.add(R.drawable.canada);
CountryFlag.add(R.drawable.china);
CountryFlag.add(R.drawable.france);
CountryFlag.add(R.drawable.germany);
CountryFlag.add(R.drawable.iran);
CountryFlag.add(R.drawable.italy);
CountryFlag.add(R.drawable.japan);
CountryFlag.add(R.drawable.korea);
CountryFlag.add(R.drawable.mexico);
CountryFlag.add(R.drawable.netherlands);
adapter = new GridAdapter(this.getActivity(),CountryList, CountryFlag);
mygrid = (GridView)rootView.findViewById(R.id.gridview1);
mygrid.setAdapter(adapter);
mygrid.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
// TODO Auto-generated method stub
}
}
);
return rootView;
}
}
----------- Creating Full Screen --------
在布局文件夹中创建 fullscreen.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
</RelativeLayout>
>
创建FullScreen.java片段
public class Fullscreen extends Fragment{ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle
savedInstanceState)
{ View rootView = inflater.inflate(R.layout.fullscreen.xml, container, false);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
return convertView; }
我是新来的android..我的英语一点:( 我想开发多窗格应用程序。 两个片段 "Gridview" 和 "Full screen" 我知道多窗格,但我不知道多窗格中的 Gridview 和全屏。 因为 ListView 的所有示例。 请帮助我
这个应用程序很适合我,但太复杂了= http://www.codeproject.com/Articles/779293/Building-Dynamic-UI-for-Android-Devices
如果我正确理解你的问题,这是一个简单的实现
------------ 创建 GridView ------------
- 对于 GridView,您需要一个用于 GridView 对象的适配器和用于列的图像,例如使用国家/地区列表和国旗图像,
在 res 中创建可绘制文件夹并在可绘制文件夹中添加国旗图像
在 res/layout
中创建 gridlayout.xml<RelativeLayout android:id="@+id/relativeLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:background="@drawable/border" android:padding="5dp"> <ImageView android:id="@+id/gridimage" android:layout_height="65dp" android:layout_width="65dp" android:src="@drawable/icon" android:layout_alignParentTop="true" android:layout_centerHorizontal="true"> </ImageView> <TextView android:id="@+id/gridtext" android:text="TextView" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/imageView1" android:layout_marginTop="2dp" android:layout_centerHorizontal="true" android:textSize="18sp" android:ellipsize="marquee"></TextView> </RelativeLayout>
在 res/Layout 文件夹中创建 gridrow.xml
<GridView android:id="@+id/gridView1" android:layout_height="wrap_content" android:layout_width="match_parent" android:numColumns="auto_fit" android:horizontalSpacing="10dp" android:verticalSpacing="10dp"> </GridView>
创建GridAdapter.javaclass
public class GridAdapter extends BaseAdapter { private ArrayList<String> CountryList; private ArrayList<Integer> CountryFlag; private Activity activity; public GridAdapter(Activity activity,ArrayList<String> CountryList, ArrayList<Integer> CountryFlag){ super();this.CountryList = CountryList; this.CountryFlag = CountryFlag; this.activity = activity;} @Override public int getCount() { return CountryList.size(); } @Override public String getItem(int position) { return CountryList.get(position); } @Override public long getItemId(int position) { return 0; } public static class ViewHolder { public ImageView imgViewFlag; public TextView txtViewTitle; } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder view; LayoutInflater inflator = activity.getLayoutInflater(); if(convertView==null) { view = new ViewHolder(); convertView = inflator.inflate(R.layout.gridview_row, null); view.txtViewTitle = (TextView) convertView.findViewById(R.id.gridtext); view.imgViewFlag = (ImageView) convertView.findViewById(R.id.gridimage); convertView.setTag(view); } else { view = (ViewHolder) convertView.getTag(); } view.txtViewTitle.setText(CountryList.get(position)); view.imgViewFlag.setImageResource(CountryFlag.get(position)); return convertView; }
}
- 创建片段 GridViewActivty
public class GridViewActivty 扩展 Fragment { private ArrayList CountryList = new ArrayList(); private ArrayList CountryFlag = new ArrayList(); 私有 GridView mygrid; 私有 GridAdapter 适配器; 私有上下文上下文; public GridViewActivty(){} @覆盖 public 查看 onCreateView(LayoutInflater inflater, ViewGroup 容器,Bundle savedInstanceState) { 查看 rootView = inflater.inflate(R.layout.gridlayout.xml, container, false);</p> <pre><code> CountryList = new ArrayList<String>(); CountryList.add("South Africa"); CountryList.add("Spain"); CountryList.add("Canada"); CountryList.add("China"); CountryList.add("France"); CountryList.add("Germany"); CountryList.add("Iran"); CountryList.add("Italy"); CountryList.add("Japan"); CountryList.add("Korea"); CountryList.add("Mexico"); CountryList.add("Netherlands"); CountryFlag = new ArrayList<Integer>(); CountryFlag.add(R.drawable.southafrica); CountryFlag.add(R.drawable.spain); CountryFlag.add(R.drawable.canada); CountryFlag.add(R.drawable.china); CountryFlag.add(R.drawable.france); CountryFlag.add(R.drawable.germany); CountryFlag.add(R.drawable.iran); CountryFlag.add(R.drawable.italy); CountryFlag.add(R.drawable.japan); CountryFlag.add(R.drawable.korea); CountryFlag.add(R.drawable.mexico); CountryFlag.add(R.drawable.netherlands); adapter = new GridAdapter(this.getActivity(),CountryList, CountryFlag); mygrid = (GridView)rootView.findViewById(R.id.gridview1); mygrid.setAdapter(adapter); mygrid.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) { // TODO Auto-generated method stub } } ); return rootView; } }
----------- Creating Full Screen --------
在布局文件夹中创建 fullscreen.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> </RelativeLayout>
>
创建FullScreen.java片段
public class Fullscreen extends Fragment{ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fullscreen.xml, container, false); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); } return convertView; }