加入正方形Item的网格示例
This commit is contained in:
parent
df4a4c6b95
commit
6242026fda
|
@ -577,6 +577,20 @@
|
|||
android:screenOrientation="portrait"
|
||||
android:windowSoftInputMode="stateAlwaysHidden|adjustResize" />
|
||||
|
||||
<!-- 正方形Item的网格DEMO -->
|
||||
<activity
|
||||
android:name=".sample.gridview.SquareAutoFitGridviewActivity"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize"
|
||||
android:label="@string/SquareAutoFitGridviewActivity"
|
||||
android:screenOrientation="portrait"
|
||||
android:windowSoftInputMode="stateAlwaysHidden|adjustResize" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="com.zftlive.android.SAMPLE_CODE" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<!-- 静态注册短信广播接收器 -->
|
||||
<receiver android:name=".sample.sms.SMSBroadcastReceiver" >
|
||||
<intent-filter android:priority="2147483647" >
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
>
|
||||
<GridView
|
||||
android:id="@+id/gv_square"
|
||||
android:background="#cccccc"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:columnWidth="@dimen/itemSize"
|
||||
android:gravity="center"
|
||||
android:horizontalSpacing="10dp"
|
||||
android:verticalSpacing="10dp"
|
||||
android:numColumns="2"
|
||||
android:scrollbars="none"
|
||||
android:stretchMode="columnWidth"
|
||||
/>
|
||||
</RelativeLayout>
|
|
@ -0,0 +1,34 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.zftlive.android.view.SquareLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv_icon"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scaleType="fitXY"
|
||||
android:contentDescription="@null"
|
||||
android:src="@drawable/default_icon" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:singleLine="true"
|
||||
android:ellipsize="none"
|
||||
android:paddingLeft="5dp"
|
||||
android:paddingRight="5dp"
|
||||
android:gravity="center"
|
||||
android:text="@string/AutoGainFormActivity"
|
||||
android:textColor="@color/blue"
|
||||
android:textSize="20sp" />
|
||||
|
||||
<View
|
||||
android:id="@+id/press"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/selector_gridview_item" />
|
||||
|
||||
</com.zftlive.android.view.SquareLayout>
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<dimen name="itemSize">140dp</dimen>
|
||||
</resources>
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<dimen name="itemSize">140dp</dimen>
|
||||
</resources>
|
|
@ -148,4 +148,5 @@
|
|||
<color name="darkblue">#00008B</color><!--暗蓝色 -->
|
||||
<color name="navy">#000080</color><!--海军色 -->
|
||||
<color name="black">#000000</color><!--黑色 -->
|
||||
<color name="black_alpha">#70000000</color><!--黑色 -->
|
||||
</resources>
|
||||
|
|
|
@ -13,4 +13,6 @@
|
|||
<dimen name="table_width">135dp</dimen>
|
||||
<dimen name="table_height">40dp</dimen>
|
||||
<!-- table_fix_headers(end) -->
|
||||
|
||||
<dimen name="itemSize">140dp</dimen>
|
||||
</resources>
|
|
@ -23,6 +23,7 @@
|
|||
<string name="PulldownViewActivity">下拉ScrollView背景回弹效果</string>
|
||||
<string name="FadingActionBar">FadingActionBar官方DEMO</string>
|
||||
<string name="PullToReresh">PullToReresh官方DEMO</string>
|
||||
<string name="SquareAutoFitGridviewActivity">正方形Item的网格</string>
|
||||
<!-- Android样例锦集label(结束) -->
|
||||
|
||||
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
package com.zftlive.android.sample.basic;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
|
||||
import com.zftlive.android.R;
|
||||
import com.zftlive.android.base.BaseActivity;
|
||||
import com.zftlive.android.common.ActionBarManager;
|
||||
import com.zftlive.android.tools.ToolDateTime;
|
||||
import com.zftlive.android.tools.ToolLocation;
|
||||
import com.zftlive.android.tools.ToolPhone;
|
||||
|
||||
|
@ -19,6 +21,8 @@ import com.zftlive.android.tools.ToolPhone;
|
|||
public class BasicTestActivity extends BaseActivity implements View.OnClickListener{
|
||||
|
||||
private Button btn_opengps, btn_call,btn_contact,btn_setting,btn_carema,btn_photo;
|
||||
private boolean flag = true;
|
||||
private Thread task = null;
|
||||
|
||||
@Override
|
||||
public int bindLayout() {
|
||||
|
@ -49,6 +53,12 @@ public class BasicTestActivity extends BaseActivity implements View.OnClickListe
|
|||
@Override
|
||||
public void doBusiness(Context mContext) {
|
||||
|
||||
|
||||
|
||||
task = new Thread(new ThreadTask());
|
||||
task.start();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -80,11 +90,28 @@ public class BasicTestActivity extends BaseActivity implements View.OnClickListe
|
|||
ToolPhone.toCameraActivity(getContext(), 88);
|
||||
break;
|
||||
case R.id.btn_photo:
|
||||
ToolPhone.toImagePickerActivity(getContext(), 77);
|
||||
// ToolPhone.toImagePickerActivity(getContext(), 77);
|
||||
flag = false;
|
||||
task.interrupt();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class ThreadTask implements Runnable{
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while(flag){
|
||||
Log.e(TAG, "Thread ID "+Thread.currentThread().getId() + "-->"+ToolDateTime.gainCurrentDate("yyyy-MM-dd HH:mm:ss"));
|
||||
try {
|
||||
Thread.sleep(3 * 1000);
|
||||
} catch (InterruptedException e) {
|
||||
Log.e(TAG, "线程被打断!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,155 @@
|
|||
package com.zftlive.android.sample.gridview;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.GridView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.zftlive.android.R;
|
||||
import com.zftlive.android.base.BaseActivity;
|
||||
import com.zftlive.android.base.BaseAdapter;
|
||||
import com.zftlive.android.common.ActionBarManager;
|
||||
import com.zftlive.android.tools.ToolAlert;
|
||||
import com.zftlive.android.tools.ToolImage;
|
||||
|
||||
/**
|
||||
* 正方形Item的gridview样例
|
||||
* @author 曾繁添
|
||||
* @version 1.0
|
||||
*
|
||||
*/
|
||||
public class SquareAutoFitGridviewActivity extends BaseActivity {
|
||||
|
||||
private GridView gv_square;
|
||||
private MyGridAdapter mAdapter;
|
||||
private String imageURLs[] = new String[]{
|
||||
"http://www.daqianduan.com/wp-content/uploads/2014/12/kanjian.jpg",
|
||||
"http://www.daqianduan.com/wp-content/uploads/2014/11/capinfo.jpg",
|
||||
"http://www.daqianduan.com/wp-content/uploads/2014/11/mi-2.jpg",
|
||||
"http://www.daqianduan.com/wp-content/uploads/2014/10/dxy.cn_.png",
|
||||
"http://www.daqianduan.com/wp-content/uploads/2014/10/xinhua.jpg",
|
||||
"http://www.daqianduan.com/wp-content/uploads/2014/09/job.jpg",
|
||||
"http://www.daqianduan.com/wp-content/uploads/2013/06/ctrip.png",
|
||||
"http://www.daqianduan.com/wp-content/uploads/2014/09/ideabinder.png",
|
||||
"http://www.daqianduan.com/wp-content/uploads/2014/05/ymatou.png",
|
||||
"http://www.daqianduan.com/wp-content/uploads/2014/03/west_house.jpg",
|
||||
"http://www.daqianduan.com/wp-content/uploads/2014/03/youanxianpin.jpg",
|
||||
"http://www.daqianduan.com/wp-content/uploads/2014/02/jd.jpg",
|
||||
"http://www.daqianduan.com/wp-content/uploads/2013/11/wealink.png",
|
||||
"http://www.daqianduan.com/wp-content/uploads/2013/09/exmail.jpg",
|
||||
"http://www.daqianduan.com/wp-content/uploads/2013/09/alipay.png",
|
||||
"http://www.daqianduan.com/wp-content/uploads/2013/08/huaqiangbei.png",
|
||||
"http://www.daqianduan.com/wp-content/uploads/2013/06/ctrip.png",
|
||||
"http://www.daqianduan.com/static/img/thumbnail.png",
|
||||
"http://www.daqianduan.com/wp-content/uploads/2013/06/bingdian.png",
|
||||
"http://www.daqianduan.com/wp-content/uploads/2013/04/ctrip-wireless.png"
|
||||
};
|
||||
private String titles[] = new String[]{
|
||||
"前端开发工程师",
|
||||
"Web前端工程师(北京-海淀)",
|
||||
"更关注用户前端体验(北京)",
|
||||
"丁香园求多枚Web",
|
||||
"新华网招中高级",
|
||||
"好声音母公司梦响强音文化",
|
||||
"携程网国际业务部",
|
||||
"ideabinder",
|
||||
"海外购物公司洋码头",
|
||||
"金山软件-西山居",
|
||||
"优安鲜品招Web前端",
|
||||
"京东招聘Web前端开",
|
||||
"若邻网(上海)急聘程师",
|
||||
"腾讯广州研发线邮箱部)",
|
||||
"支付宝招募资深交互设计师",
|
||||
"华强北商城招聘前端开发工程师",
|
||||
"携程(上海)框架研发部",
|
||||
"阿里巴巴中文站招聘前端开发",
|
||||
"多途网络科端开发工程师",
|
||||
"携程无线前端团队招聘 直接"
|
||||
};
|
||||
|
||||
@Override
|
||||
public int bindLayout() {
|
||||
return R.layout.activity_block_gridview;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initView(View view) {
|
||||
gv_square = (GridView) findViewById(R.id.gv_square);
|
||||
gv_square.setOnItemClickListener(new OnItemClickListener() {
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view,
|
||||
int position, long id) {
|
||||
Map<String,Object> itemData = (Map<String,Object>)parent.getItemAtPosition(position);
|
||||
ToolAlert.toastShort(getContext(), itemData.get("title")+"");
|
||||
}
|
||||
});
|
||||
mAdapter = new MyGridAdapter();
|
||||
ToolImage.initImageLoader(getContext());
|
||||
|
||||
//初始化带返回按钮的标题栏
|
||||
String strCenterTitle = getResources().getString(R.string.SquareAutoFitGridviewActivity);
|
||||
ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doBusiness(Context mContext) {
|
||||
//构造数据
|
||||
for (int i = 0; i < 20; i++) {
|
||||
Map<String,Object> rowData = new LinkedHashMap<String,Object>();
|
||||
rowData.put("imageUrl", imageURLs[i]);
|
||||
rowData.put("title", titles[i]);
|
||||
mAdapter.addItem(rowData);
|
||||
}
|
||||
gv_square.setAdapter(mAdapter);
|
||||
mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resume() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
ToolImage.clearCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* 网格适配器
|
||||
*
|
||||
*/
|
||||
protected class MyGridAdapter extends BaseAdapter{
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
ViewHolder mViewHolder;
|
||||
if(null == convertView){
|
||||
convertView = getLayoutInflater().inflate(R.layout.activity_block_gridview_item, null);
|
||||
mViewHolder = new ViewHolder();
|
||||
mViewHolder.iv_icon = (ImageView)convertView.findViewById(R.id.iv_icon);
|
||||
mViewHolder.tv_title = (TextView)convertView.findViewById(R.id.tv_title);
|
||||
convertView.setTag(mViewHolder);
|
||||
}else{
|
||||
mViewHolder = (ViewHolder)convertView.getTag();
|
||||
}
|
||||
//设置数据
|
||||
Map<String,Object> rowData = (Map)getItem(position);
|
||||
ToolImage.getImageLoader().displayImage((String)rowData.get("imageUrl"), mViewHolder.iv_icon);
|
||||
mViewHolder.tv_title.setText((String)rowData.get("title"));
|
||||
return convertView;
|
||||
}
|
||||
|
||||
class ViewHolder{
|
||||
ImageView iv_icon;
|
||||
TextView tv_title;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue