Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android:水平线布局项目之间的细线_Android_Imageview_Line_Android Linearlayout - Fatal编程技术网

Android:水平线布局项目之间的细线

Android:水平线布局项目之间的细线,android,imageview,line,android-linearlayout,Android,Imageview,Line,Android Linearlayout,我在自己制作的zoomview中得到了一个表格布局。 当我平移/拖动tablelayout时,我有时会看到它们之间有一条很细的线 在ImageView(水平和垂直)中我可以看到背景色,如何删除这条线?我还尝试使用列而不是水平线性布局,同样的问题 <ZoomView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:la

我在自己制作的zoomview中得到了一个表格布局。 当我平移/拖动tablelayout时,我有时会看到它们之间有一条很细的线 在ImageView(水平和垂直)中我可以看到背景色,如何删除这条线?我还尝试使用列而不是水平线性布局,同样的问题

<ZoomView 
xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:id="@+id/zoomView">

    <TableLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#FFFFFF"
        android:weightSum="2"
        android:shrinkColumns="0,1">
        <TableRow
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_weight="1">
            <LinearLayout
            android:orientation="horizontal"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:weightSum="2">
            <ImageView
                android:src="@drawable/parkZoomOut"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:scaleType="fitEnd"
                android:layout_weight="1"/>
            <ImageView
                android:src="@drawable/parkZoomOut2"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:scaleType="fitEnd"
                android:layout_weight="1" />
                </LinearLayout>

        </TableRow>
        <TableRow
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_weight="1">
             <LinearLayout
            android:orientation="horizontal"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:weightSum="2">
            <ImageView
                android:src="@drawable/parkZoomOut3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:scaleType="fitStart"
                 android:layout_weight="1" />
            <ImageView
                android:src="@drawable/parkZoomOut4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:scaleType="fitStart" 
                 android:layout_weight="1"/>
                </LinearLayout>
        </TableRow>
    </TableLayout>
</ZoomView>

我对此没有答案(但怀疑Android可能使用整数像素定位带来舍入误差),但我建立了一个库,用于显示可能对您有用的大图像:是的,我看到了您的库,我很想使用它,但我不知道如何将其集成到xamarin中,没有jar文件,移植到C#需要很长时间,我想你有没有办法将它集成到Xamarin中,或者你有jar文件?我真的很想使用你的图书馆你能分享这个屏幕吗?如果你能帮我找到一个方法,我甚至愿意付钱。。。
public class ZoomView : LinearLayout
{

    private static  String TAG = "ZoomLayout";
    private static  float MIN_ZOOM = 1.0f;
    private static  float MAX_ZOOM = 7.0f;

    private enum Mode 
    {
        NONE,
        DRAG,
        ZOOM
    }
    private Mode mode = Mode.NONE;

    private static float scale = 1.0f;
    private static float lastScaleFactor = 0f;
    private float initialScale=0f;
    // Where the finger first  touches the screen
    private float startX = 0f;
    private float startY = 0f;

    // How much to translate the canvas
    private float dx = 0f;
    private float dy = 0f;
    private float prevDx = 0f;
    private float prevDy = 0f;

    private int screenHeight=0;
    private int screenWidth=0;

    ScaleGestureDetector scaleDetector;


    public ZoomView (Context context) :    
    base (context)
    {
        Initialize (context);    
    }

    public ZoomView (Context context, IAttributeSet attrs) :base (context,attrs)    
    {
        Initialize (context);    
    }

    public ZoomView (Context context, IAttributeSet attrs, int defStyle) :base (context, attrs, defStyle)
    {
        Initialize (context);
    }
    void Initialize (Context context)
    {
        scaleDetector = new ScaleGestureDetector(context, new MyScaleListener());
    }

    public void SetInitialScale()
    {
        var metrics = Resources.DisplayMetrics;

        double originalPictureWidth = 2498;
        double originalPictureHeight = 2048;

        screenWidth = metrics.WidthPixels;
        screenHeight = metrics.HeightPixels-105;//dit nog omzetten van dp

        double sc = screenWidth / originalPictureWidth;
        var height = sc * originalPictureHeight;
        var rsc = screenHeight/height; 
        //Console.Write ("scale");
        //Console.WriteLine (rsc.ToString ());
        scale = (float)rsc;
        initialScale = scale;
        ApplyScaleAndTranslation();
        MIN_ZOOM = scale;

    }

    public bool OnTouch(View v, MotionEvent e)
    {
        return OnTouchEvent(e);
    }

    public override bool OnTouchEvent(MotionEvent e)
    {
        switch (e.Action)
        {
        case MotionEventActions.Down:
            Console.WriteLine ("down");
                    if (scale >= MIN_ZOOM) 
                    {
                        mode = Mode.DRAG;
                        startX = e.GetX() - prevDx;
                        startY = e.GetY() - prevDy;
                    }
                    break;
                case MotionEventActions.Move:
                Console.WriteLine("move");
                    if (mode == Mode.DRAG) 
                    {
                        dx = e.GetX() - startX;
                        dy = e.GetY() - startY;
                    }
                    break;
                case MotionEventActions.Pointer2Down:
                Console.WriteLine("pointerdown");
                    mode = Mode.ZOOM;
                    break;
                case MotionEventActions.Pointer2Up:
                Console.WriteLine("pointerup");
                    mode = Mode.DRAG;
                    break;
                case MotionEventActions.Up:
                Console.WriteLine("up");
                    mode = Mode.NONE;
                    prevDx = dx;
                    prevDy = dy;
                    break;
                   }

        scaleDetector.OnTouchEvent(e);

        if ((mode == Mode.DRAG && scale >= MIN_ZOOM) || mode == Mode.ZOOM) 
        {
            Parent.RequestDisallowInterceptTouchEvent(true);
            float maxDx = (Child().Width  - (Child().Width / scale)) / 2 * scale;

            float maxDy = 0;
            if (scale != initialScale)
            {
                var sc = scale/initialScale;
                maxDy = (Child().Height  - (Child().Height / sc)) / 2 * sc;
            }


            //Console.WriteLine("uo");
            //Console.WriteLine (scale.ToString ());
            //Console.WriteLine (maxDy);
            //Console.WriteLine (dy);
            dx = Math.Min(Math.Max(dx, -maxDx), maxDx);
            dy = Math.Min(Math.Max(dy, -maxDy), maxDy);

            ApplyScaleAndTranslation();
        }
        return true;
    }


    private void ApplyScaleAndTranslation() 
    {
        Child().ScaleX=scale;
        Child().ScaleY=scale;
        Child().TranslationX=dx;
        Child().TranslationY=dy;
    }

    private View Child() 
    {
        return GetChildAt(0);
    }

    private class MyScaleListener : ScaleGestureDetector.SimpleOnScaleGestureListener
    {

    public override bool OnScale(ScaleGestureDetector scaleDetector)
    {
        float scaleFactor = scaleDetector.ScaleFactor;

        if (lastScaleFactor == 0 || (Math.Sign(scaleFactor) == Math.Sign(lastScaleFactor)))
            {
            scale *= scaleFactor;
                Console.Write ("scalefactor");
                Console.WriteLine(scale.ToString());
            scale = Math.Max(MIN_ZOOM, Math.Min(scale, MAX_ZOOM));
            lastScaleFactor = scaleFactor;
        } 
        else
        {
            lastScaleFactor = 0;
        }
        return true;
    }

    public override bool OnScaleBegin(ScaleGestureDetector s)
    {
        return true;
    }

    public override void OnScaleEnd(ScaleGestureDetector s)
    {

    }

}

}}