本文实例为大家分享了Android实现QQ图片说说照片选择的具体代码,供大家参考,具体内容如下
效果展示
<强> 强>布局文件
布局是很简单的,一个显示数据表格,直接上布局:
布局/activity_add_photo.xml
& lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比; & lt; LinearLayout xmlns: android=" http://schemas.android.com/apk/res/android " android: layout_width=" match_parent " android: layout_height=" match_parent " 面向android:=按怪薄北? & lt;使用 android: layout_width=" match_parent " android: layout_height=" 60 dp " android:背景=" # 00 bb9c”比; & lt; TextView android: layout_width=" wrap_content " android: layout_height=" wrap_content " android: layout_centerInParent=" true " android:文本="写动态” android: textAppearance=" & # 63; android: attr/textAppearanceLarge” android:输入textColor=癅android:颜色/白色/比; & lt; TextView android: id=癅 + id/发送” android: layout_width=" wrap_content " android: layout_height=" wrap_content " android: layout_alignParentRight=" true " android: layout_centerVertical=" true " android: layout_marginRight=" 10 dp” android:文本="发送” android: textAppearance=" & # 63; android: attr/textAppearanceLarge” android:输入textColor=癅android:颜色/白色/比; & lt;/RelativeLayout> LinearLayout & lt; android: layout_width=" match_parent " android: layout_height=" match_parent " android: layout_margin=" 16 dp " 面向android:=按怪薄北? EditText & lt; android: layout_width=" match_parent " android: layout_height=" 100 dp” android:启用=" false " android: focusable=" false " android:重力=岸ゼ丁? android:提示="分享您的那点新鲜事儿……” android: maxLines=" 5 "/比; LinearLayout & lt; android: layout_width=" match_parent " android: layout_height=" match_parent " android:填充=" 5 dp "比; & lt;显示数据表格 android: id=癅 + id/显示数据表格” android: layout_width=" match_parent " android: layout_height=" wrap_content " android: numColumns=" 4 "/比; & lt;/LinearLayout> & lt;/LinearLayout> & lt;/LinearLayout> >之前/activity_add_photo_gv_items布局。xml使用了自定义的观点使得布局为正方形
& lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比; & lt; com.shenhua.tabhostdemo.selectimg。SquareRelativeLayout xmlns: android=" http://schemas.android.com/apk/res/android " android: layout_width=" wrap_content " android: layout_height=皐rap_content”比; & lt; ImageView android: id=癅 + id/main_gridView_item_photo” android: layout_width=" match_parent " android: layout_height=" match_parent " android: layout_centerInParent=" true " android: contentDescription=" @null " android:填充=" 5 dp " android: scaleType=" fitXY "/比; & lt;复选框 android: id=癅 + id/main_gridView_item_cb” android: layout_width=" 20 dp” android: layout_height=" 20 dp” android: layout_alignParentEnd=" true " android: layout_alignParentRight=" true " android: layout_alignParentTop=" true " android: layout_margin=" 2 dp " android:背景=" @drawable/ic_delete” android: backgroundTint=" # 00 bb9c” android:按钮=" @null "/比; & lt;/com.shenhua.tabhostdemo.selectimg.SquareRelativeLayout> >之前<强>代码实现强>
SquareRelativeLayout.java:
包com.shenhua.tabhostdemo.selectimg; 进口android.content.Context; 进口android.util.AttributeSet; 进口android.widget.RelativeLayout;/* * *自定义方形布的局 *由神华> 包com.shenhua.tabhostdemo.selectimg; 进口android.content.Intent; 进口android.graphics.Bitmap; 进口android.graphics.BitmapFactory; 进口android.net.Uri; 进口android.os.Bundle; 进口android.support.annotation.Nullable; 进口android.support.v7.app.AppCompatActivity; 进口android.view.LayoutInflater; 进口android.view.View; 进口android.view.ViewGroup; 进口android.widget.AdapterView; 进口android.widget.BaseAdapter; 进口android.widget.CheckBox; 进口android.widget.GridView; 进口android.widget.ImageView; 进口android.widget.TextView; 进口android.widget.Toast; 进口com.shenhua.tabhostdemo.R; 进口java.io.ByteArrayOutputStream; 进口java.util.ArrayList; 进口并不知道;/* * *由神华> 包com.shenhua.tabhostdemo.selectimg; 进口android.annotation.TargetApi; 进口android.app.Activity; 进口android.content.ContentUris; 进口android.content.Context; 进口android.database.Cursor; 进口android.graphics.Bitmap; 进口android.graphics.BitmapFactory; 进口android.net.Uri; 进口android.os.Environment; 进口android.provider.DocumentsContract; 进口android.provider.MediaStore;/* * *由神华> & lt; uses-permission android: name=" android.permission。READ_EXTERNAL_STORAGE”/比;Android实现QQ图片说说照片选择效果