仿淘宝商品页上下拖拽滑动控件

仿淘宝商品页上下拖拽滑动控件,下拉回弹,果冻弹入

这是一个viewGroup容器,实现上下两个frameLayout拖动切换,解决与WebView、ScrollView、ListView嵌套冲突。

效果图

主要特点
1,适应横竖屏切换
2,解决与WebView、ScrollView、ListView嵌套冲突
3,高自定义
4,自动滑动
5,果冻拖拽弹回
6,自定义背景

使用步骤

导入项目

main_activity.xml布局

"http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <com.klxair.slidingupdown.view.DragLayout
        android:id="@+id/draglayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        "@+id/first"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />

        "@+id/second"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
    com.klxair.slidingupdown.view.DragLayout>

MainActivity类

package com.klxair.slidingupdown;

import com.klxair.slidingupdown.view.DragLayout;
import com.klxair.slidingupdown.view.DragLayout.ShowNextPageNotifier;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;

public class MainActivity extends AppCompatActivity {

    private Fragment1 fragment1;
    private Fragment2 fragment2;
    private DragLayout draglayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);
        initView();
    }

    /**
     * 初始化View
     */
    private void initView() {
        fragment1 = new Fragment1();
        fragment2 = new Fragment2();

        getSupportFragmentManager().beginTransaction().add(R.id.first, fragment1).add(R.id.second, fragment2).commit();

        ShowNextPageNotifier nextIntf = new ShowNextPageNotifier() {
            @Override
            public void onDragNext() {
                fragment2.initView();
            }
        };
        draglayout = (DragLayout) findViewById(R.id.draglayout);
        draglayout.setNextPageListener(nextIntf);
    }

}

Fragment1

布局文件可自己随意编写,这里就不贴出了

package com.klxair.slidingupdown;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class Fragment1 extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment1, null);
        return rootView;
    }
}

Fragment2

布局文件可自己随意编写,这里就不贴出了

package com.klxair.slidingupdown;

import com.klxair.slidingupdown.view.CustWebView;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class Fragment2 extends Fragment {

    private View progressBar;
    private CustWebView webview;
    private boolean hasInited = false;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment2, null);
        webview = (CustWebView) rootView.findViewById(R.id.fragment3_webview);
        progressBar = rootView.findViewById(R.id.progressbar);
        return rootView;
    }

    public void initView() {
        if (null != webview && !hasInited) {
            hasInited = true;
            progressBar.setVisibility(View.GONE);
            webview.loadUrl("https://www.baidu.com/");
        }
    }
}

有问题什么欢迎大家提出来。后期还会对其进行优化。

感谢大家支持!

项目地址:http://download.csdn.net/detail/ls498297458/9676760

你可能感兴趣的:(Android)