这个FragmentActivity创建了一些放在滑块(水平)中的片段。这里只显示了一个片段):
public class MainActivity2 extends FragmentActivity{
private ViewPager mPager;
private FragmentStatePagerAdapter mPagerAdapter;
private Logger mLogger;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_container);
mLogger = new Logger();
mPager = (ViewPager)findViewById(R.id.pager);
mPagerAdapter = new SliderAdapter(getSupportFragmentManager());
mPager.setAdapter(mPagerAdapter);
... //goes on with activity, the adapter is set correctly..
Logger片段用以下xml创建它的视图:
<TextView
android:id="@+id/LoggerLoTitle"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:ems="10"
android:layout_weight="2"
android:gravity="center"
android:textStyle="bold"
android:textColor="#000033"
android:textSize="16sp"
android:text="@string/logger"
android:layout_marginTop="30sp" />
<TextView
android:id="@+id/numberOutput"
android:textIsSelectable="true"
android:layout_width="0dp"
android:layout_weight="13"
android:layout_height="fill_parent"
android:gravity="top"
android:freezesText="true"
android:maxLines = "50"
android:layout_marginLeft="22dp"
android:scrollbars = "vertical"
android:layout_marginTop="45sp"/>
<Button
android:background="#80FFFFFF"
android:gravity="center"
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="fill_parent"
android:freezesText="true"
android:scrollbars = "vertical"
android:layout_marginTop="45sp"
android:textColor="#000000"
android:textStyle="bold"
android:text="@string/logger_ad"
android:onClick="whatsNew"/>
</LinearLayout>
对于API 7,除了TextView"numberOutput"不滚动并且不能被选中之外,一切都很好(所有的片段都被加载并且滑动条工作)。对于API 15,16,17来说,情况很好。任何想法?
通过在运行时获取TextView (numberOutput)并设置一个移动方法来解决这个问题:
rootView = (ViewGroup) inflater.inflate(R.layout.dicelogger_lo, container, false);
mLoggerBody = (TextView)rootView.findViewById(R.id.numberOutput);
mLoggerBody.setMovementMethod(new ScrollingMovementMethod());
我没有在文档中发现更高的api级别会自动设置任何移动方法。为什么是另一个问题