我已经在Android 2.2中的Android开发人员网站Tab Layout上创建了Tab Layout示例。虽然该示例的工作原理与我所宣传的一样,但我无法在我放置在其中一个活动中的文本视图上进行滚动。如果重要的话,TextView对象是在给定的活动中动态创建的。我试图用ScrollView在main.xml中包装组件的不同部分,但是我在启动时遇到了构建错误或强制关闭。附件是实现textViews的代码,它的xml以及main.xml文件。因为我是新手,所以无法发布图片。任何建议,非常感谢。无法在Tabhost衍生活动中滚动标签内容
的main.xml:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<!-- android:padding="5dp" -->
</LinearLayout>
</TabHost>
来源,在表所创建的我TextViews:以上活动
public class Activity2 extends Activity{
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
DisplayTexts(20);
}
private void DisplayTexts(int length){
if(length == 0)
return;
LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
for(int i = 0; i < length; i++)
{
TextView tv = new TextView(getApplicationContext());
registerForContextMenu(tv);
tv.setTextSize(30);
tv.setText("TextView " + String.valueOf(i));
tv.setLayoutParams(params);
layout.addView(tv);
tv.setId(i);
}
LinearLayout.LayoutParams layoutParam = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
this.addContentView(layout, layoutParam);
}
XML文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
</LinearLayout>
的制造建议的更改,我现在可以滚动。非常感谢您的帮助! – lshan47
很高兴为您提供帮助。如果您的答案对您有帮助,请通过检查答案左上角的绿色“正确”标记来接受答案。它可以帮助您提高接受比率,也可以帮助其他人参考此问题。 – Hiral