如何移动留下了图像视图,右android开发(2) [英] How to move a image View left and right in android development (2)

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

问题描述

我也问过这之前,但没有答案,为我工作。

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

<一个href=\"http://stackoverflow.com/questions/16952058/how-to-move-a-image-view-left-and-right-in-android-development?answertab=active#tab-top\">How移动留下了图像视图,右android开发

推荐答案

请使用code:

在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"/>

然后在把这个code中的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);
}

这会给你你在找什么。

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

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