那位有好办法呀?现在是想在一个 view 中动态创建一些 button 组件, 如果用linearlayout 一行满后其它 button 会看不到了.
所以有什么 view 或可 content 可以实现让其它的 button 自动换到下一行显示.谢谢了.
所以有什么 view 或可 content 可以实现让其它的 button 自动换到下一行显示.谢谢了.
解决方案 »
- Android:TextView:同时调用setLines与setMaxLines(或者setLines与setMinLines)方法均有问题
- 高分请教:Android为什么我的Button点两下才起作用
- Eclipse下java编程, 能不能实现可视化编程?
- android fragment 的界面切换事件替换为按钮事件
- 定时下载,求完整代码
- SurfaceView与滑动页面冲突问题,求解决
- 线程同步问题
- c/s架构请教,请高手指教
- 我是一名技术小白,求一枚师傅。
- Android中用C++实现Binder进程间通信编程过程
- 请教个关于dlna镜像传输的问题
- android引CGLIB 报java.lang.VerifyError
用其它布局也可以, 但其它的 layout 好像也没有比较简单的办法来实现这个要求吧.
用这个可以, 但是也有一个问题. 如当某一个 button 的 text 很长时, 就会有同列界面空间浪费问题.
我看到 HTC 手机中短信接收人删除 view 中有这个功能, 我和其望的比较接近, 不知哪位研究过, 共享一下经验感谢不尽!!
把按钮添加到下一个lineLayout中
在create Button 时 是不能用getwidth()获得按钮的宽度的啊 , 请教
或者改android源码吧。
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
public class LineBreakLayout extends ViewGroup
{
private final static String TAG = "LineBreakLayout";
private final static int VIEW_MARGIN = 2;
public LineBreakLayout(Context context)
{
super(context);
// TODO Auto-generated constructor stub
}
public LineBreakLayout(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
} public LineBreakLayout(Context context, AttributeSet attrs)
{
super(context, attrs);
// TODO Auto-generated constructor stub
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
//Log.d(TAG, "widthMeasureSpec = " + widthMeasureSpec+ " heightMeasureSpec" + heightMeasureSpec);
for (int index = 0; index < getChildCount(); index++)
{
final View child = getChildAt(index);
// measure
child.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
@Override
protected void onLayout(boolean arg0, int arg1, int arg2, int arg3, int arg4)
{
//Log.d(TAG, "changed = " + arg0 + " left = " + arg1 + " top = " + arg2+ " right = " + arg3 + " botom = " + arg4);
final int count = getChildCount();
int row = 0;// which row lay you view relative to parent
int lengthX = arg1; // right position of child relative to parent
int lengthY = arg2; // bottom position of child relative to parent
for (int i = 0; i < count; i++)
{
final View child = this.getChildAt(i);
int width = child.getMeasuredWidth();
int height = child.getMeasuredHeight();
lengthX += width + VIEW_MARGIN;
lengthY = row * (height + VIEW_MARGIN) + VIEW_MARGIN + height
+ arg2;
// if it can't drawing on a same line , skip to next line
if (lengthX > arg3)
{
lengthX = width + VIEW_MARGIN + arg1;
row++;
lengthY = row * (height + VIEW_MARGIN) + VIEW_MARGIN + height
+ arg2;
}
child.layout(lengthX - width, lengthY - height, lengthX, lengthY);
}
}
}
都是靠左的