Android 问题:无法在 ScrollView 上添加超过 11 个视图
这是我在 stackOverflow 上的第一个问题,所以让我们开始吧:
我有这个布局:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<LinearLayout
android:id="@+id/widget31"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView
android:id="@+id/set_reader_tv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Reader Settings:"
android:typeface="serif"
android:textStyle="bold"
android:textSize="20sp"
android:gravity="left"
>
</TextView>
<LinearLayout
android:id="@+id/widget42"
android:layout_width="fill_parent"
android:layout_height="2px"
android:orientation="vertical"
android:background="#88ffffff"
android:layout_marginBottom="10px"
/>
<CheckBox
android:id="@+id/set_auto_mark_cb"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Auto mark as read"
>
</CheckBox>
<CheckBox
android:id="@+id/set_auto_mark_cb12"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Auto mark as read"
>
</CheckBox>
<CheckBox
android:id="@+id/set_unread_cb"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Show unread only"
>
</CheckBox>
<CheckBox
android:id="@+id/set_skip_cb"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Mark as read on skip"
>
</CheckBox>
<TextView
android:id="@+id/set_click_tv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="On feed content click, do:"
android:typeface="serif"
android:textStyle="bold"
android:textSize="20sp"
android:layout_marginTop="10px"
>
</TextView>
<LinearLayout
android:id="@+id/widget41"
android:layout_width="fill_parent"
android:layout_height="2px"
android:orientation="vertical"
android:background="#88ffffff"
android:layout_marginBottom="10px"
/>
<Spinner
android:id="@+id/set_action_spin"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5px"
android:layout_marginBottom="5px"
android:layout_marginLeft="5px"
android:layout_marginRight="5px"
android:drawSelectorOnTop="true"
android:layout_gravity="center_horizontal"
>
</Spinner>
<TextView
android:id="@+id/set_account_tv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Change reader account:"
android:typeface="serif"
android:textStyle="bold"
android:textSize="20sp"
android:gravity="left"
android:layout_marginTop="10px"
>
</TextView>
<LinearLayout
android:id="@+id/widget42"
android:layout_width="fill_parent"
android:layout_height="2px"
android:orientation="vertical"
android:background="#88ffffff"
android:layout_marginBottom="10px"
/>
<Button
android:id="@+id/set_account_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Change">
</Button>
</LinearLayout>
</ScrollView>
但是如果我在这个布局上添加一个视图(CheckBox、TextView、LinearLayout)(不是在 RunTime 中,在 CodeTime 中,我还没有尝试在 RunTime 中这样做) ),当我打开这个(setContentView(sv))时,它说:
窗口已聚焦,忽略焦点增益:com.android.internal.view.IInputMethodClient$Stub$Proxy@462fa1b0
我可以更改任何视图,但无法添加新视图。
这是我的膨胀代码:
LayoutInflater inf = getLayoutInflater();
ScrollView sv = (ScrollView)inf.inflate(R.layout.layout_settings, null);
//More code here
那么,ScrollView 可以承载的最大视图有多少?
不管怎样,谢谢。
This is my first question on stackOverflow, so lets go:
I have this layout:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<LinearLayout
android:id="@+id/widget31"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView
android:id="@+id/set_reader_tv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Reader Settings:"
android:typeface="serif"
android:textStyle="bold"
android:textSize="20sp"
android:gravity="left"
>
</TextView>
<LinearLayout
android:id="@+id/widget42"
android:layout_width="fill_parent"
android:layout_height="2px"
android:orientation="vertical"
android:background="#88ffffff"
android:layout_marginBottom="10px"
/>
<CheckBox
android:id="@+id/set_auto_mark_cb"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Auto mark as read"
>
</CheckBox>
<CheckBox
android:id="@+id/set_auto_mark_cb12"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Auto mark as read"
>
</CheckBox>
<CheckBox
android:id="@+id/set_unread_cb"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Show unread only"
>
</CheckBox>
<CheckBox
android:id="@+id/set_skip_cb"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Mark as read on skip"
>
</CheckBox>
<TextView
android:id="@+id/set_click_tv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="On feed content click, do:"
android:typeface="serif"
android:textStyle="bold"
android:textSize="20sp"
android:layout_marginTop="10px"
>
</TextView>
<LinearLayout
android:id="@+id/widget41"
android:layout_width="fill_parent"
android:layout_height="2px"
android:orientation="vertical"
android:background="#88ffffff"
android:layout_marginBottom="10px"
/>
<Spinner
android:id="@+id/set_action_spin"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5px"
android:layout_marginBottom="5px"
android:layout_marginLeft="5px"
android:layout_marginRight="5px"
android:drawSelectorOnTop="true"
android:layout_gravity="center_horizontal"
>
</Spinner>
<TextView
android:id="@+id/set_account_tv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Change reader account:"
android:typeface="serif"
android:textStyle="bold"
android:textSize="20sp"
android:gravity="left"
android:layout_marginTop="10px"
>
</TextView>
<LinearLayout
android:id="@+id/widget42"
android:layout_width="fill_parent"
android:layout_height="2px"
android:orientation="vertical"
android:background="#88ffffff"
android:layout_marginBottom="10px"
/>
<Button
android:id="@+id/set_account_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Change">
</Button>
</LinearLayout>
</ScrollView>
But if i add one more view (CheckBox, TextView, LinearLayout) on this layout (not in RunTime, in CodeTime, i havent tried to do it in RunTime), when i open this (setContentView(sv)), it says:
Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@462fa1b0
I can change any view, but i cant add new one.
This is my inflate code:
LayoutInflater inf = getLayoutInflater();
ScrollView sv = (ScrollView)inf.inflate(R.layout.layout_settings, null);
//More code here
So, there's any maximum of view that a ScrollView can host?
Thx Anyway.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为在
LinearLayout
中添加更多小部件/组件没有问题。据我所知,ScrollView 的唯一限制是它只能有一个孩子。为什么要夸大布局?您只需使用 setContentView(R.layout.layout_settings) 即可。我尝试了你的 xml 文件,我可以毫无问题地添加更多视图。I see no problem in having more widgets/components inside your
LinearLayout
. As far as I know, the only limitation ofScrollView
is that it should only have one child. Why are you inflating the layout? You can just usesetContentView(R.layout.layout_settings)
. I tried your xml file and I can add more views without any problem.