gpt4 book ai didi

java - 动态添加多个水平线性布局到选项卡

转载 作者:行者123 更新时间:2023-11-30 03:19:00 26 4
gpt4 key购买 nike

我有一个案例,我需要将 2 个 TextView 添加到水平 LinearLayout,并多次复制该结构。

例如:

|TextView1| |TextView2|
| TextView 1| |TextView2|
等..

我目前的代码是:

        public View createTabContent(String tag){
LinearLayout mainTabLayout = new LinearLayout(Result.this);
mainTabLayout.setOrientation(LinearLayout.HORIZONTAL);
mainTabLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));

for( Object param : mainHashMap.values() ){
String key = param.toString();

LinearLayout linLayout = new LinearLayout(Result.this);
linLayout.setOrientation(LinearLayout.HORIZONTAL);

linLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));

TextView tvKey = new TextView(Result.this);
tvKey.setText(key);
tvKey.setTextSize(15);
linLayout.addView(tvKey);
try{
String member = this.transformMember(key);
Method method = mainClass.getMethod("get" + member);

TextView tvValue = new TextView(Result.this);
tvValue.setText((method.invoke(mainData) != null) ? method.invoke(dvlaData).toString() : "");
tvValue.setTextSize(10);
linLayout.addView(tvValue);
} catch (InvocationTargetException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
} catch (NoSuchMethodException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
} catch (IllegalAccessException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
Log.d("ResultActivity", "adding to view");
mainTabLayout.addView(linLayout);
}
return mainTabLayout;
}

Log.d 显示它正在运行它需要的每个项目,但是 TabContent 只显示最后一个 LinearLayout。它会覆盖之前添加到 mainTabLayout 的 LinearLayouts。

我希望这是有道理的...

最佳答案

尝试将 mainTabLayout 方向设置为垂直而不是水平

关于java - 动态添加多个水平线性布局到选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19496142/

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