在Android编程方式设置滚动型+固定键用的setText。 [英] Set ScrollView + Fixed Button Programatically on Android with setText.

查看:158
本文介绍了在Android编程方式设置滚动型+固定键用的setText。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是在这一点上卡住:我想有一个滚动视图+底部固定的按钮,但通过编程的方式!我可以'T使用XML去一些技术原因。

I' m at this point stuck : I want to have a scrollview + a fixed button at the bottom, but Programatically Way ! I can' t go with XML for some technical reason.

其实我有这样的:

//Is it really usefull Relative View?
RelativeLayout layout = new RelativeLayout(this);
ScrollView sv = new ScrollView(this);
sv.setId(2);
// What is it? RelativeLayout.LayoutParams?
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
    RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, sv.getId());
sv.setLayoutParams(new ViewGroup.LayoutParams(480, 800));
layout.addView(saveButton, lp);
layout.addView(sv);

我做的第一件第3页谷歌在固定按钮和滚动型的Andr​​oid编程

I do the first 3 page Google on "fixed button and scrollview Android programatically"

在Android林初学,所以,别犹豫我的code一些提示作出评论)

Im beginner on Android, so, don' t hesitate to comment on my code some hints ;)

THX对您有所帮助。

Thx for your help.

推荐答案

试试这个

LinearLayout layout = new LinearLayout(this);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
        LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setLayoutParams(lp);

ScrollView scroll = new ScrollView(this);
LinearLayout.LayoutParams slp = new LinearLayout.LayoutParams(
        LayoutParams.FILL_PARENT,0, 1.0f);
scroll.setLayoutParams(slp);

Button btn = new Button(this);
ViewGroup.LayoutParams blp = new ViewGroup.LayoutParams(
        LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
btn.setLayoutParams(blp);
btn.setText("Click Me");

layout.addView(scroll);
layout.addView(btn);

setContentView(layout);

这篇关于在Android编程方式设置滚动型+固定键用的setText。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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