(Android)Fragment 的XML不能实现ScrollView上下滑动求指导

移动开发 码拜 8年前 (2016-09-16) 1547次浏览
import java.util.ArrayList;
import java.util.List;
import com.example.beilex.Adapter.Art_adapter;
import com.example.beilex.entity.PublicEntity;
import com.example.beilex_activty.R;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
public class Dance_Fragment extends Fragment {
	private View view;
	private GridView gv;
	private Art_adapter madapter;
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// System.out.println("OneFragment  onCreateView");
		view = inflater.inflate(R.layout.dance_fragments, container, false);
		intview(view);
		Exhibition();
		gv.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int number,
					long arg3) {
				// TODO Auto-generated method stub
				Log.i("点击编号", "编号为:"+number);
			}
		});
		return view;
	}
	private void intview(View v) {
		// TODO Auto-generated method stub
		gv = (GridView) v.findViewById(R.id.dance_mygridview_gv);

	}
	public void Exhibition(){
		List<PublicEntity>list= new  ArrayList<PublicEntity>();
		PublicEntity pe= new PublicEntity();
		pe.setName("小儿舞蹈");
		//pe.setBitmap(bitmap);
		for(int i=0;i<12;i++){
			list.add(pe);
		}

		madapter=new Art_adapter(getActivity(), list);
		gv.setAdapter(madapter);
	}
}  
//以上只是例子
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >
            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="舞蹈"
                android:textSize="24sp" />
            <com.example.beilex.quote.MyGridView
                android:id="@+id/dance_mygridview_gv"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dip"
                android:gravity="center"
                android:horizontalSpacing="0.0dip"
                android:listSelector="@null"
                android:numColumns="2"
                android:scrollbars="none"
                android:stretchMode="columnWidth"
                android:verticalSpacing="0.0dip" />
        </LinearLayout>
    </ScrollView>
</LinearLayout>
解决方案

40

嵌套了gridview,滑动会有冲突的,根据gridview的项目数,计算gridview的高度,这样才能滚动scrollview

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明(Android)Fragment 的XML不能实现ScrollView上下滑动求指导
喜欢 (0)
[1034331897@qq.com]
分享 (0)