Android - Zoom imagen

 
Vista:
sin imagen de perfil

Zoom imagen

Publicado por Tony (5 intervenciones) el 25/08/2016 18:12:31
Hola, mi problema es el siguiente: Tengo un grupo de imágenes dentro de un Absolutelayout y este a su vez esta dentro de un Linearlayout, mediante un botón puedo hacer zoom al Linearlayout para que las imágenes se vean mas grandes pero tengo el problema de que cada vez que hago zoom se come un poco del margen superior e izquierdo del layout. ¿Alguien sabría decirme como puedo hacer para que no se coma esos margenes?

Codigo:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<LinearLayout
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:paddingLeft="30dp">
 
        <LinearLayout
            android:id="@+id/ly"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/scrollView"
                android:scrollbarAlwaysDrawHorizontalTrack="true">
                <HorizontalScrollView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/horizontalScrollView" >
                    <AbsoluteLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent">
 
                        <ImageView
                            android:id="@+id/imageView1"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:src="@drawable/perrobebe"/>
                        <ImageView
                            android:id="@+id/imageView2"
                            android:layout_width="22dp"
                            android:layout_height="22dp"
                            android:layout_x="69dp"
                            android:layout_y="60dp"
                            android:src="@drawable/circulo"/>
 
                    </AbsoluteLayout>
 
 
                </HorizontalScrollView>
            </ScrollView>
        </LinearLayout>
    </LinearLayout>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
public class MainActivity extends AppCompatActivity {
 
    ZoomButton zoom1,zoom2;
    ImageView img1,img2;
    LinearLayout ly;
 
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
 
        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
 
 
        zoom1 = (ZoomButton) findViewById(R.id.zoomButton1);
        zoom2 = (ZoomButton) findViewById(R.id.zoomButton2);
        img1 = (ImageView) findViewById(R.id.imageView1);
        img2 = (ImageView) findViewById(R.id.imageView2);
        ly=(LinearLayout) findViewById(R.id.ly);
 
        zoom1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
 
                float x = ly.getScaleX();
                float y = ly.getScaleY();
 
                if(x<3){
 
                    ly.setScaleX(x+1);
                    ly.setScaleY(y+1);
 
                }
 
 
 
            }
        });
        zoom2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
 
                float x = ly.getScaleX();
                float y = ly.getScaleY();
 
                if(x>1){
 
                    ly.setScaleX( x - 1 );
                    ly.setScaleY( 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);
    }
}

Muchas gracias
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder