如何移动图像在Android开发中查看左和右(2) [英] How to move a image View left and right in android development (2)

查看:177
本文介绍了如何移动图像在Android开发中查看左和右(2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前问过这个问题,但没有答案对我有用。

I have asked this before but no answers that worked for me.

如何移动图像在Android开发中向左和向右查看

推荐答案

请使用以下代码:

在main.xml中:

In main.xml:

<ImageView 
    android:id="@+id/imageview"
    android:layout_width="wrap_content"
    android:layout_gravity="center"
    android:layout_height="wrap_content"
    android:background="@drawable/ic_launcher"/>

<Button 
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Left"
    android:onClick="onClickLeft"/>

<Button 
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Right"
    android:onClick="onClickRight"/>

然后在.java文件中放这个代码:

And then in the .java file put this code:

public void onClickLeft(View view){
    ImageView t = (ImageView) findViewById(R.id.imageview);

    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

        params.gravity=3;

        t.setLayoutParams(params);
}

public void onClickRight(View view){
    ImageView t = (ImageView) findViewById(R.id.imageview);

    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

        params.gravity=5;

        t.setLayoutParams(params);
}

这将给你你要找的东西。

This will give you what you are looking for.

这篇关于如何移动图像在Android开发中查看左和右(2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆