Android Studio平台中如何获得利用GridLayout布局的按钮Button的坐标啊?求大神赐教!!
1个回答
推荐于2016-01-19 · 知道合伙人数码行家
可以叫我表哥
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数:25897
获赞数:1464989
2010年毕业于北京化工大学北方学院计算机科学与技术专业毕业,学士学位,工程电子技术行业4年从业经验。
向TA提问 私信TA
关注
展开全部
参考下: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<images.length; 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);
}
}
代码布局应该差不多吧:
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<images.length; 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);
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
微测检测5.10
2023-05-10 广告
2023-05-10 广告
您好!建议咨 深圳市微测检测有限公司,已建立起十余个专业实验室,企业通过微测检测就可以获得一站式的测试与认 证解决方案;(EMC、RF、MFi、BQB、QI、USB、安全、锂电池、快充、汽车电子EMC、汽车手机互 联、语音通话质量),认证遇...
点击进入详情页
本回答由微测检测5.10提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询