Android GridView 위 챗 모멘트 이미지 모방
GridView 를 이용 하면 더 이상 어 울 리 지 않 습 니 다.GridView 는 그림 의 수량 을 동적 으로 불 러 올 수 있 고 규칙 적 입 니 다.다음은 자신의 생각 을 말씀 드 리 겠 습 니 다.
첫째,먼저 GridView 의 item
<com.view.SquareLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="@+id/item_grida_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:layout_margin="@dimen/tinyest_space">
</ImageView>
</com.view.SquareLayout>
이곳 의 Square Layout 레이아웃 은 사용자 정의 입 니 다.자세 한 설명 을 드 리 겠 습 니 다.하위 항목 에는 정사각형 레이아웃 에 그림 이 새 겨 져 있 습 니 다.
다음 사용자 정의 어댑터
프로젝트 수요 가 다 르 기 때문에 자신 이 정의 하 는 어댑터 는 평소에 사용 하 는 것 과 다 르 기 때문에 원본 코드 를 붙 이지 않 습 니 다.대체로 그림 을 로 컬 에 다운로드 하고 Imageloader 로 불 러 옵 니 다.하지만 업로드 에 실패 한 것 과 새로 만 든 것 이 있어 서 다 릅 니 다.
3.마지막 으로 사용 하 는 Activity 에서 설정
noScrollgridview = (GridView) findViewById(R.id.noScrollgridview);
noScrollgridview.setNumColumns(3); // 3
// adapter
picAdapter = new PictureAdapter(this, 1, appItem_file);
noScrollgridview.setAdapter(picAdapter);
//
int size = appItemFile.getFiles().split(",").length;
if (size==1){
noScrollgridview.setNumColumns(1);
}
else if (size==2){
noScrollgridview.setNumColumns(2);
}
else if (size>2){
noScrollgridview.setNumColumns(3);
}
picAdapter.notifyDataSetChanged();
기본적으로 GridView 의 열 수 를 3 으로 설정 하고 그림 의 수량 에 따라 동적 으로 열 수 를 설정 합 니 다.마지막 으로 Square Layout 의 소스 코드 를 붙 여 분석 해 보 겠 습 니 다.
/**
*
*/
public class SquareLayout extends RelativeLayout {
public SquareLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public SquareLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SquareLayout(Context context) {
super(context);
}
@SuppressWarnings("unused")
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// For simple implementation, or internal size is always 0.
// We depend on the container to specify the layout size of
// our view. We can't really know what it is since we will be
// adding and removing different arbitrary views and do not
// want the layout to change as this happens.
setMeasuredDimension(getDefaultSize(0, widthMeasureSpec),
getDefaultSize(0, heightMeasureSpec));
// Children are just made to fill our space.
int childWidthSize = getMeasuredWidth();
int childHeightSize = getMeasuredHeight();
//
heightMeasureSpec = widthMeasureSpec = MeasureSpec.makeMeasureSpec(
childWidthSize, MeasureSpec.EXACTLY);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
여 기 는 주로 onMeasure()방법 을 다시 썼 습 니 다.높이 와 폭 을 설 치 했 습 니 다.주의해 야 할 것 은 Square Layout 를 사용 할 때 높이 와 폭 을 모두 match 로 설정 해 야 합 니 다.parent。이렇게 하면 GridView 의 모든 항목 을 채 울 수 있 습 니 다.다음은 스티커 를 보 여 드 리 겠 습 니 다.
ImgeView 의 scaleType 속성 은 FitXY 를 설정 하면 사각형 레이아웃 이 가득 하고 center 가 가운데 로 표 시 됩 니 다.
자세히 말씀 해 주세요.
1)center:원본 그림 의 크기 를 유지 하고 ImageView 의 중심 에 표시 합 니 다.원본 그림 의 size 가 ImageView 의 size 보다 크 면 부분 재단 처 리 를 초과 합 니 다.
2)centerCrop:이미지 뷰 전 체 를 채 우 는 것 을 목적 으로 이미지 뷰 의 중심 을 이미지 뷰 의 중심 에 맞 추 는 등 비례 를 확대 하여 이미지 뷰 를 채 울 때 까지(이미지 뷰 의 너비 와 높이 를 모두 채 워 야 한 다 는 뜻)원 도 는 이미지 뷰 를 초과 한 부분 을 재단 처리 합 니 다.
3)center Inside:원 그림 을 완전히 표시 하 는 것 을 목적 으로 그림 의 내용 을 전체 가운데 로 표시 하고 원 그림 의 size 너비(높이)를 비례 에 따라 축소 하거나 ImageView 의 너비(높이)보다 작 게 표시 합 니 다.원본 그림 의 size 자체 가 ImageView 의 size 보다 작 으 면 원본 그림 의 size 는 아무런 처리 도 하지 않 고 중앙 에 ImageView 에 표 시 됩 니 다.
4)matrix:원본 그림 의 크기 를 바 꾸 지 않 고 ImageView 의 왼쪽 상단 부터 원본 그림 을 그립 니 다.원본 그림 이 ImageView 를 초과 한 부분 을 재단 처리 합 니 다.
5)fitCenter:원본 그림 을 비례 에 따라 ImageView 의 ImageView 높이 로 확대 하거나 축소 하여 중간 에 표시 합 니 다.
6)fitEnd:원본 그림 을 비례 에 따라 ImageView 의 높이 로 확대(축소)하여 ImageView 의 아래 부분 에 표시 합 니 다.
7)fitStart:원본 그림 을 비례 에 따라 ImageView 의 높이 로 확대(축소)하여 ImageView 의 상단 위치 에 표시 합 니 다.
8)fitXY:원 도 를 지 정 된 크기 로 View 에 표시 하고 그림 을 늘 려 서 원 비례 를 유지 하지 않 고 ImageView 를 채 웁 니 다.
본 고 는 이미《Android 위 챗 개발 튜 토리 얼 집계》로 정리 되 었 으 니,여러분 의 학습 과 독 서 를 환영 합 니 다.
이상 은 본문의 전체 내용 이 므 로 여러분 의 학습 에 도움 이 되 기 를 바 랍 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Bitrise에서 배포 어플리케이션 설정 테스트하기이 글은 Bitrise 광고 달력의 23일째 글입니다. 자체 또는 당사 등에서 Bitrise 구축 서비스를 사용합니다. 그나저나 며칠 전 Bitrise User Group Meetup #3에서 아래 슬라이드를 발표했...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.