Android 는 ScrollView 에 포 함 된 ListView 와 GridView 의 내용 이 불완전 하 게 표 시 된 문 제 를 해결 합 니 다.
7478 단어 scrollviewgridviewlistview불완전 표시
나의 XML 부분 코드 는 다음 과 같다.
<ScrollView
android:layout_height="match_parent"
android:layout_width="fill_parent"
android:scrollbars="none"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#23000000"
android:orientation="vertical"
android:paddingTop="-1dp" >
<android.support.v4.view.ViewPager
android:id="@+id/home_pager"
android:layout_width="fill_parent"
android:layout_height="100dp" >
</android.support.v4.view.ViewPager>
<GridView
android:id="@+id/gv_home"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:numColumns="5"
android:paddingBottom="10dp"
android:paddingTop="13dp" >
</GridView>
<LinearLayout
android:id="@+id/ll_clickin"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@drawable/shape_home"
android:orientation="horizontal" >
<ImageView
android:layout_width="85dp"
android:layout_height="wrap_content"
android:src="@drawable/click_in" />
<TextView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:singleLine="true"
android:text=" , !"
android:textSize="18sp" />
</LinearLayout>
<ListView
android:id="@+id/list_home"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ffffff" >
</ListView>
</LinearLayout>
</ScrollView>
이렇게 나 와 요.그 중 에 Listview 와 GridView 가 미 끄 러 질 수 있어 요.다 보이 지 않 아 요.자기가 쓴 방법 을 써 서 모든 항목 이 나 왔어요.
그럼 더 이상 쓸데없는 소리 하지 말고 제 가 개인 적 으로 연구 한 코드 를 올 려 주세요.
우선 ListView 에 관 한 것 입 니 다.(이 방법 은 SetAdapter()방법 으로 실행 되 어야 합 니 다.)
컨트롤 검색 입 니 다.
list_home = (ListView) view.findViewById(R.id.list_home);
list_home.setAdapter(new MyListViewAdapter(grideview_List));
list_home.setFocusable(false);// ,
//setAdapter
getListViewSelfHeight(list_home);
getListView SelfHeight(ListView youListview)입 니 다.
public void getListViewSelfHeight(ListView listView) {
// ListView Adapter
ListAdapter listAdapter = listView.getAdapter();
//
if (listAdapter == null) {
return;
}
//
int totalHeight = 0;
for (int i = 0, len = listAdapter.getCount(); i < len; i++) {
// listAdapter.getCount()
View listItem = listAdapter.getView(i, null, listView);
// measure 0
listItem.measure(0, 0);
totalHeight += listItem.getMeasuredHeight();
}
//
ViewGroup.LayoutParams params = listView.getLayoutParams();
//listAdapter.getCount() - 1 listView.getDividerHeight()
params.height = totalHeight+ (listView.getDividerHeight() * (listAdapter.getCount() - 1));
listView.setLayoutParams(params);
}
다음은 GridView 의 방법 입 니 다.ListView 의 측정 방법 과 거의 같 습 니 다. 하지만 listView 는 단일 항목 이 므 로 열 걱정 없 이 GridView 에 게 물 어보 면 자신의 줄 과 자신의 열 을 나 누 어야 하기 때문에 주의해 야 합 니 다.
gv_home = (GridView) view.findViewById(R.id.gv_home);
gv_home.setSelector(new ColorDrawable(Color.TRANSPARENT));
home_pager.setFocusable(false);
gv_home.setAdapter(new MyGrigeViewAdapter(grideview_List));
getGridViewSelfHeight(gv_home);
다음은 getGridView SelfHeight(GridView you GrideView)입 니 다.
public void getGridViewSelfhetght(GridView gridView) {
// GridView Adapter
ListAdapter adapter = gridView.getAdapter();
if (adapter == null) {
return;
}
int totalHeight = 0;
for (int i = 0, len = adapter.getCount(); i < len; i++) {
// gridView.getCount()
View listItem = adapter.getView(i, null, gridView);
// View
listItem.measure(0, 0);
//
//5 5 Xml android:numColumns="5"
//FontDisplayUtil.dip2px(MyGlobalApplication.getContext(),3)
totalHeight += listItem.getMeasuredHeight()/5+FontDisplayUtil.dip2px(MyGlobalApplication.getContext(),3);
}
ViewGroup.LayoutParams params = gridView.getLayoutParams();
params.height = totalHeight;
gridView.setLayoutParams(params);
}
다음은 FontDisplayUtil 류 입 니 다.
import android.content.Context;
/**
* dp、sp 、 px
*/
public class FontDisplayUtil {
/**
* px dip dp ,
*/
public static int px2dip(Context context, float pxValue) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (pxValue / scale + 0.5f);
}
/**
* dip dp px ,
*/
public static int dip2px(Context context, float dipValue) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (dipValue * scale + 0.5f);
}
/**
* px sp ,
*/
public static int px2sp(Context context, float pxValue) {
final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
return (int) (pxValue / fontScale + 0.5f);
}
/**
* sp px ,
*/
public static int sp2px(Context context, float spValue) {
final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
return (int) (spValue * fontScale + 0.5f);
}
}
총결산이상 은 이 글 의 모든 내용 입 니 다.본 고의 내용 이 여러분 의 학습 이나 업무 에 어느 정도 참고 학습 가 치 를 가지 기 를 바 랍 니 다.여러분 의 저희 에 대한 지지 에 감 사 드 립 니 다.더 많은 내용 을 알 고 싶다 면 아래 링크 를 보 세 요.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
수평listview를 실현하고 수평listview가scrollview에서 발생하는 미끄럼 충돌을 해결합니다수평 ListView를 구현하고 ScrollView에서 수평 ListView의 슬라이딩 충돌 해결 먼저 위 그림: 해결된 문제는 다음과 같습니다. 1) 수평 슬라이딩을 구현하는 ListView입니다.AdapterVi...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.