Android Scrollview + horizantal scrollview + zoomcontrols

时间:2015-07-19 22:43:40

标签: android

我正在使用学习zoomcontrols。我现在处于开始的机器人。

如果我离得更近,它似乎不是图片的一部分。代码如下。请帮帮我

我不想要pinc zoom ..我想要简单的按钮缩放。我很抱歉我的英语:(我希望你能理解我..

XML

<LinearLayout xmlns:android="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"
tools:context=".MainActivity">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1">

    <HorizontalScrollView
        android:layout_width="match_parent"
        android:layout_height="fill_parent">

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ImageView
                android:id="@+id/resim"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
        </ScrollView>

    </HorizontalScrollView>
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="100dp">

    <ZoomControls
        android:id="@+id/zoomControls"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal" />

</LinearLayout>

和java

  package com.example.kusem.ikiliscrollldenemeleri;

import android.annotation.TargetApi;
import android.os.Build;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.text.Layout;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.ScrollView;
import android.widget.ZoomControls;


public class MainActivity extends ActionBarActivity {

ImageView iv;
ZoomControls zoom;
ScrollView sv;
HorizontalScrollView hsv;


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

    zoom= (ZoomControls) findViewById(R.id.zoomControls);
    iv= (ImageView) findViewById(R.id.resim);

   // hsv= (HorizontalScrollView) findViewById(R.id.hsv);



    iv.setImageResource(R.drawable.resim2);

    zoom.setOnZoomInClickListener(new View.OnClickListener() {
        @TargetApi(Build.VERSION_CODES.HONEYCOMB)
        @Override
        public void onClick(View v) {
            float x = iv.getScaleX();
            float y = iv.getScaleY();

            iv.setScaleX((float)(x+1));
            iv.setScaleY((float)(y+1));



        }
    });

    zoom.setOnZoomOutClickListener(new View.OnClickListener() {

        @TargetApi(Build.VERSION_CODES.HONEYCOMB)
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub


            float x = iv.getScaleX();
            float y = iv.getScaleY();

            iv.setScaleX((float) (x-1));
            iv.setScaleY((float) (y-1));


        }
    });



}


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

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
    }
}

提前感谢您的帮助..

0 个答案:

没有答案