Android移动条像滑动抽屉

时间:2014-01-29 17:29:13

标签: java android slider slideshow

我尝试在androind应用程序中实现以下视图。

在我的程序中,我想将主要活动分成两部分。 现在它不起作用。我想,两个之间的界线 活动中的窗口是可移动的,并且该行可以划分整个屏幕 不同的比例。不仅要显示整个窗口或另一个窗口。

了解enter link description here

的图片

我的程序看起来像: MainActivity.java

    package dva.checkin;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMyLocationChangeListener;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;


import android.graphics.Color;
import android.location.Location;
import android.os.Bundle;
import android.app.Activity;

import android.util.Log;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class MainActivity extends Activity implements
        OnMyLocationChangeListener {

    private boolean firstStart = true;
    private GoogleMap map;
    private LinearLayout listView;
    private LinearLayout mapView;
    private View divider;
    private float touchActionDownX;
    private float touchActionDownY;

    private ListView dataList;
    private void initCustomList() {

        dataList = (ListView) findViewById(R.id.locations_list);

        dataList.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View v,
                    final int position, long id) {
            }
        });
    }



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initCustomList();


        listView = (LinearLayout) findViewById(R.id.list_view);
        mapView = (LinearLayout) findViewById(R.id.map_view);

        divider = (View) findViewById(R.id.divider);
        divider.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent event) {
                switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:

                    divider.setBackgroundColor(Color.parseColor("#FF0000"));
                    touchActionDownX = event.getRawX();
                    touchActionDownY = event.getRawY();
                    Log.i("DOWN", "" + touchActionDownX + " ; "
                            + touchActionDownY);
                    break;
                case MotionEvent.ACTION_MOVE: {
                    // Log.i("test","Move");

                    float touchActionMoveX = event.getRawX();
                    float touchActionMoveY = event.getRawY();

                    Log.i("MOVE", "down " + touchActionDownX + " ; "
                            + touchActionDownY);
                    Log.i("MOVE", "curr " + touchActionMoveX + " ; "
                            + touchActionMoveY);

                    if (touchActionMoveX < touchActionDownX) {
                        Log.i("MOVE UP", ""
                                + (touchActionMoveX - touchActionDownX));
                        // UP
                        LinearLayout.LayoutParams lpar = (LinearLayout.LayoutParams) listView
                                .getLayoutParams();
                        LinearLayout.LayoutParams mpar = (LinearLayout.LayoutParams) mapView
                                .getLayoutParams();

                        if (lpar.weight > 0.2) {
                            lpar.weight -= 0.1;
                            mpar.weight += 0.1;
                        }

                        listView.setLayoutParams(lpar);
                        mapView.setLayoutParams(mpar);
                    } else if (touchActionMoveX >= touchActionDownX) {
                        // DOWN
                        Log.i("MOVE DOWN", ""
                                + (touchActionDownX - touchActionMoveX));
                        LinearLayout.LayoutParams lpar = (LinearLayout.LayoutParams) listView
                                .getLayoutParams();
                        LinearLayout.LayoutParams mpar = (LinearLayout.LayoutParams) mapView
                                .getLayoutParams();

                        if (mpar.weight > 0.2) {
                            mpar.weight -= 0.1;
                            lpar.weight += 0.1;
                        }

                        listView.setLayoutParams(lpar);
                        mapView.setLayoutParams(mpar);
                    }

                    touchActionDownX = touchActionMoveX;
                    touchActionDownY = touchActionMoveY;

                    break;
                }
                case MotionEvent.ACTION_UP:
                    divider.setBackgroundColor(Color.parseColor("#00FF00"));
                    break;
                }

                return true;
            }
        });

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public void onMyLocationChange(Location location) {

        if (firstStart) {
            CameraPosition cameraPosition = new CameraPosition.Builder()
                    .target(new LatLng(location.getLatitude(), location
                            .getLongitude())).zoom(18).build();

            map.animateCamera(CameraUpdateFactory
                    .newCameraPosition(cameraPosition));
            firstStart = false;
        }

    }

}

比activity_main.xml

<?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" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1.0"
    android:orientation="vertical"
    android:id="@+id/list_view" >

    <Button
        android:id="@+id/checkin"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/checkin" 
        android:onClick="checkIn"/>

    <ListView
        android:id="@+id/locations_list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:paddingTop="5dp" >
    </ListView>

</LinearLayout>
 <View android:id="@+id/divider"
           android:layout_height="15dip" 
           android:background="#00ff00"
           android:layout_width="fill_parent"  />
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1.0"
    android:orientation="vertical" 
    android:id="@+id/map_view">


</LinearLayout>

</LinearLayout>

和AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="dva.checkin"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="18" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <activity
            android:name="dva.checkin.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name="dva.checkin.CheckinDetailsActivity"
            android:parentActivityName="dva.checkin.MainActivity" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="dva.checkin.MainActivity" />
        </activity>

        <activity android:name=".DisplayImageActivity"></activity>

    </application>

</manifest>

感谢您的建议!

0 个答案:

没有答案