在scrollup上显示图库

时间:2018-02-07 14:27:59

标签: android xml

我想要的是当我向上滚动滚动视图时,图库应该打开,当我向下滚动时,表面视图(相机)应该像 OLX 一样可见。我在image.hope中解释了我的要求。我以适当的方式解释了我的问题。

我在此图片中解释了我的要求

enter image description here

我还发布了我的xml代码,让您正确理解。

    <?xml version="1.0" encoding="utf-8"?>
     <RelativeLayout 
         xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:app="http://schemas.android.com/apk/res-auto"
          xmlns:tools="http://schemas.android.com/tools"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          tools:context="com.example.ali.ansofexperts.Question_Photo">
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        />
        <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/camera_preview">

        </FrameLayout>
         <ScrollView
         android:layout_width="fill_parent"
         android:id="@+id/scrollView"
         android:fillViewport="true"
         android:layout_height="fill_parent"
          >
        <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
        <LinearLayout
            android:layout_width="fill_parent"
            android:minHeight="400dp"
            android:layout_height="wrap_content"
            android:id="@+id/click"
            android:orientation="horizontal">

        </LinearLayout>

        <GridView xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/gridview" android:layout_width="fill_parent"
            android:layout_height="fill_parent" android:columnWidth="90dp"
            android:numColumns="auto_fit" android:verticalSpacing="10dp"
            android:horizontalSpacing="10dp" android:stretchMode="columnWidth"
            android:gravity="center" android:layout_gravity="bottom"
            android:layout_marginTop="400dp"></GridView>
           </RelativeLayout>
       </ScrollView>
   </RelativeLayout>

2 个答案:

答案 0 :(得分:1)

我发布此初学者参考

<强> https://android-arsenal.com/details/1/5987

本参考资料有关于我的问题的完整解决方案,希望这会有所帮助。

答案 1 :(得分:0)

试试这个

/** A basic Camera preview class */
public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback {
    private SurfaceHolder mHolder;
    private Camera mCamera;

    public CameraPreview(Context context, Camera camera) {
        super(context);
        mCamera = camera;

        // Install a SurfaceHolder.Callback so we get notified when the
        // underlying surface is created and destroyed.
        mHolder = getHolder();
        mHolder.addCallback(this);
        // deprecated setting, but required on Android versions prior to 3.0
        mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }

    public void surfaceCreated(SurfaceHolder holder) {
        // The Surface has been created, now tell the camera where to draw the preview.
        try {
            mCamera.setPreviewDisplay(holder);
            mCamera.startPreview();
        } catch (IOException e) {
            Log.d(TAG, "Error setting camera preview: " + e.getMessage());
        }
    }

    public void surfaceDestroyed(SurfaceHolder holder) {
        // empty. Take care of releasing the Camera preview in your activity.
    }

    public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
        // If your preview can change or rotate, take care of those events here.
        // Make sure to stop the preview before resizing or reformatting it.

        if (mHolder.getSurface() == null){
          // preview surface does not exist
          return;
        }

        // stop preview before making changes
        try {
            mCamera.stopPreview();
        } catch (Exception e){
          // ignore: tried to stop a non-existent preview
        }

        // set preview size and make any resize, rotate or
        // reformatting changes here

        // start preview with new settings
        try {
            mCamera.setPreviewDisplay(mHolder);
            mCamera.startPreview();

        } catch (Exception e){
            Log.d(TAG, "Error starting camera preview: " + e.getMessage());
        }
    }
}
  

参考此文档,您可以使用camer ... gallery实现surfaceview   派对你可以尝试自己..   https://developer.android.com/guide/topics/media/camera.html

     

https://github.com/googlesamples/android-Camera2Video