gpt4 book ai didi

android - 如何更改线性布局中 View 的位置。?

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:06:56 26 4
gpt4 key购买 nike

所以我有一个已经填充了子项的线性布局。有没有办法改变其中一个 child 所在的位置?

如果有任何帮助,我正在尝试交换他们之间的观点。

final LinearLayout parrent = (LinearLayout)findViewById(R.id.llWidgetScreen);
final LinearLayout Delailah = new LinearLayout(this);
Delailah.setLayoutParams(new android.widget.LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
AppWidgetHostView wedgy = attachWidget(mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo));
Delailah.addView(wedgy);
final Button btn = new Button(this);
btn.setLayoutParams(new android.widget.LinearLayout.LayoutParams((int)(20*scale +0.5f), android.view.ViewGroup.LayoutParams.FILL_PARENT, 0f));
btn.setOnLongClickListener(new OnLongClickListener() {

@Override
public boolean onLongClick(View v) {
parrent.removeView(Delailah);
return false;
}
});
btn.setBackgroundColor(mainColor);
btn.setText(parrent.getChildCount()+1+"");
btn.setTextColor(textColor);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(ReadyForDrag==0)
{
btn.setBackgroundColor(actiColor);
ReadyForDrag++;
DragPosition1=Integer.parseInt(btn.getText().toString());
}
else if(ReadyForDrag==1)
{
btn.setBackgroundColor(actiColor);
ReadyForDrag=0;
LinearLayout v1 = (LinearLayout)parrent.getChildAt(DragPosition1);
LinearLayout v2 = (LinearLayout)parrent.getChildAt(Integer.parseInt(btn.getText().toString()));
//move view 2 to position 1
//move view 1 to position 2
}
}
});
Delailah.addView(btn);
parrent.addView(Delailah);

最佳答案

您可以使用 ViewGroup.removeView(View)ViewGroup.addView(View child, int index, ViewGroup.LayoutParams params)为了这。

关于android - 如何更改线性布局中 View 的位置。?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7504531/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com