android studio按坐标布局,Android Studio平台中如何获得利用GridLayout布局的按钮Button的坐标啊?求大神赐教!!...

满意答案

02ae427d08e371d7e90d5b995e828d6d.png

Maowenbo1993

推荐于 2016.01.19

参考下:http://tech.techweb.com.cn/thread-537085-1-1.html

代码布局应该差不多吧:

package com.example.dong;

import android.app.Activity;

import android.graphics.Color;

import android.graphics.drawable.Drawable;

import android.os.Bundle;

import android.os.storage.OnObbStateChangeListener;

import android.view.animation.Animation;

import android.view.animation.AnimationUtils;

import android.view.animation.TranslateAnimation;

import android.widget.Button;

import android.widget.ImageButton;

import android.widget.ImageView;

import android.widget.LinearLayout;

import android.widget.LinearLayout.LayoutParams;

import android.widget.ScrollView;

public class N extends Activity{

public int images[] = new int[]{R.drawable.jingse,R.drawable.jingse1,

R.drawable.jingse2, R.drawable.jingse3, R.drawable.jingse4,

R.drawable.jingse5, R.drawable.jingse6, R.drawable.jingse7};

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

LinearLayout layout = new LinearLayout(this);

layout.setOrientation(LinearLayout.VERTICAL);

LayoutParams param = new LayoutParams(

LayoutParams.WRAP_CONTENT,

LayoutParams.WRAP_CONTENT);

ImageView image1 = new ImageView(this);

for(int i=0; i

image1.setBackgroundResource(images);

}

//Animation animation = AnimationUtils.loadAnimation(this, R.anim.trans);、、R.anim.trans为加载的动画布局文件

Animation animation = new TranslateAnimation(

Animation.RELATIVE_TO_SELF, -1.0f,

Animation.RELATIVE_TO_SELF, 0.0f,

Animation.RELATIVE_TO_SELF, 0.0f,

Animation.RELATIVE_TO_SELF, 0.0f);

animation.setDuration(2000);

animation.setFillAfter(true);

animation.setRepeatCount(-1);

//其中,参数repeatCount为重复执行的次数。如果设置为n,则动画将执行n+1次。

// animation.initialize(2, 2, 30, 30);

image1.startAnimation(animation);

animation.startNow(); //启动动画(可省略)

// animation.cancel();//取消动画

layout.addView(image1, param);

ImageView image2 = new ImageView(this);

image2.setImageDrawable(this.getResources().getDrawable(R.drawable.jingse5));

layout.addView(image2);

ImageView image3 = new ImageView(this);

image3.setImageDrawable(this.getResources().getDrawable(R.drawable.jingse6));

// LayoutParams para;

// para = image.getLayoutParams();

//

// para.height = 300;

// para.width = 300;

// imageView.setLayoutParams(para)

LayoutParams p = new LayoutParams(

LayoutParams.WRAP_CONTENT,

LayoutParams.WRAP_CONTENT);

p.width = 100;

p.height = 100;

image3.setLayoutParams(p);

// LinearLayout.LayoutParams pa = (LayoutParams) image3.getLayoutParams();

// pa.height = 300;

// pa.width = 300;

// image3.setLayoutParams(pa);

layout.addView(image3);

LinearLayout layout2 = new LinearLayout(this);

Button btn = new Button(this);

layout2.addView(btn, param);

layout.addView(layout2);

// layout.setBackgroundColor(Color.parseColor("#ffffff"));

LayoutParams params = new LayoutParams(

ScrollView.LayoutParams.FILL_PARENT,

ScrollView.LayoutParams.FILL_PARENT

);

ScrollView scro = new ScrollView(this);

scro.addView(layout, param);

//scro.setBackgroundColor(Color.parseColor("#F5F5DC"));

//scro.setBackgroundDrawable(getResources().getDrawable(R.drawable.jingse));

setContentView(scro);

}

}

00分享举报

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值