相关疑难解决方法(0)

如何避免"IllegalStateException:Scrollview只能托管一个直接孩子"?

ScrollView在我的Android布局中使用但它显示

IllegalStateException "Scrollview can host only one direct child"

我怎样才能避免这种异常?

崩溃信息:

07-19 15:58:22.308 21372 21372 D AndroidRuntime: Shutting down VM
07-19 15:58:22.313 21372 21372 E AndroidRuntime: FATAL EXCEPTION: main
07-19 15:58:22.313 21372 21372 E AndroidRuntime: Process: com.languoguang.helloworld, PID: 21372
07-19 15:58:22.313 21372 21372 E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.languoguang.helloworld/com.languoguang.helloworld.plugin_homeadd.activity.AddDeviceWifiSettingActivity}: android.view.InflateException: Binary XML file line #254: ScrollView can host only one direct child
07-19 15:58:22.313 21372 21372 E AndroidRuntime:        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3190)
07-19 15:58:22.313 21372 21372 E AndroidRuntime: …
Run Code Online (Sandbox Code Playgroud)

android scrollview

22
推荐指数
2
解决办法
1万
查看次数

java.lang.IllegalStateException:ScrollView只能托管一个直接子项

我只是尝试通过添加scrollview添加滚动浏览此布局的功能,但每次我尝试加载布局时,我都会收到一条错误,指出"java.lang.IllegalStateException:ScrollView只能托管一个直接子项",我不确定为什么.

任何建议都非常感谢.

资源:

<?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="wrap_content"
    android:layout_weight="1"
    android:orientation="vertical" >

    <RelativeLayout>

        <View
            android:layout_width="1dp"
            android:layout_height="5dp" >
        </View>

        <ScrollView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1" >

            <com.google.android.youtube.player.YouTubePlayerView
                android:id="@+id/youtubeplayerview"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" />

            <View
                android:layout_width="1dp"
                android:layout_height="5dp" >
            </View>

            <TextView
                android:id="@+id/textView1a"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Isaac Daniel at CNN Anderson Cooper"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <TextView
                android:id="@+id/textView2a"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="by idconex"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <TextView
                android:id="@+id/textView3a"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="675,000,000 views"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <com.google.android.youtube.player.YouTubePlayerView
                android:id="@+id/youtubeplayerview2"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" />

            <TextView
                android:id="@+id/textView1b"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Rage Against The Machine - Bulls on Parade"
                android:textAppearance="?android:attr/textAppearanceMedium" …
Run Code Online (Sandbox Code Playgroud)

java xml android android-ui android-layout

15
推荐指数
1
解决办法
4万
查看次数

Android ScrollView只能托管一个直接子项

我有一个来自库的onclick监听器,它应该清除tableview中的所有行,然后将行/行添加到scrollview内的tableview.每次按下按钮时,片段都应该更改.

但是我得到:java.lang.IllegalStateException:ScrollView只能托管一个直接子项.

myactivity按钮监听器

            TrackerFragment tf = (TrackerFragment) getFragmentManager().findFragmentById(R.id.tracker1);
            tf = TrackerFragment.newInstance(listOfList.get(id).get(position));

            fragmentTransaction.add(R.id.tracker1, tf);
            fragmentTransaction.commit();
            t1 = true; //being used
            getFragmentManager().executePendingTransactions();
Run Code Online (Sandbox Code Playgroud)

跟踪片段

public class TrackerFragment extends Fragment
{
    private Dish dish;

    public static TrackerFragment newInstance(Serializable dish) 
    {
        TrackerFragment tf = new TrackerFragment();

        Bundle args = new Bundle();
        args.putSerializable("dish", dish);
        tf.setArguments(args);

        return tf;
    }

    public static TrackerFragment newInstance(Bundle bundle)
    {
        Dish dish = (Dish) bundle.getSerializable("dish");
        return newInstance(dish);
    }

    @Override
    public void onCreate(Bundle myBundle)
    {
        super.onCreate(myBundle);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup …
Run Code Online (Sandbox Code Playgroud)

android scrollview android-layout android-fragments

7
推荐指数
3
解决办法
5万
查看次数

滚动视图中的异常

在我的 Android 应用程序中,我面临着 IllegalStateException。我稍后无法重现此异常。这是堆栈跟踪

Non-fatal Exception: java.lang.IllegalStateException: ScrollView can host only one direct child
       at android.widget.ScrollView.addView(ScrollView.java:397)
       at android.support.design.widget.BaseTransientBottomBar.showView(BaseTransientBottomBar.java:436)
       at android.support.design.widget.BaseTransientBottomBar$1.handleMessage(BaseTransientBottomBar.java:178)
       at android.os.Handler.dispatchMessage(Handler.java:98)
       at android.os.Looper.loop(Looper.java:146)
       at android.app.ActivityThread.main(ActivityThread.java:5679)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:515)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
       at dalvik.system.NativeStart.main(NativeStart.java)  
Run Code Online (Sandbox Code Playgroud)

任何人请帮助我!

android scrollview

5
推荐指数
1
解决办法
2099
查看次数