我正在尝试创建一个包含 4 个按钮的页面。
当我单击一个按钮时,该按钮应保持突出显示状态, ScrollView 应出现在其下方,并带有文本并按下该按钮下方的按钮(必要时甚至关闭屏幕)。再次点击按钮后, ScrollView 将再次隐藏。
如何让 ScrollView 在单击按钮时隐藏和重新出现?
这就是我想要的样子:http://img407.imageshack.us/img407/3448/47163794.png
最佳答案
这是我最近用 ExpandableListView
所做的.这很容易。
它拥有迄今为止我在 android 中见过的最大的构造函数之一。
使用 ExpandableListView
创建布局.
<LinearLayout>
<ExpandableListView>
<!-- Set the properties, if you need to see them, let me know. -->
</ExpandableListView>
</LinearLayout>
现在在某些 View 中使用布局。
public void onCreate() {
ExpandableListView example = findViewById(/* The id of the expandable list view */);
example.setAdapter(
new SimpleExpandableListAdapter(
/* the context */,
/* the map of parents/groups */,
/* the layout to map the parents/groups to */,
/* the key to search for in the parents/groups map */,
/* the id of the textview inside the layout to map the parent/group to */,
/* the map of children */,
/* the layout to map the children to */,
/* the key to search for in the children map */,
/* the id of the textview inside the layout to map the children to */)
)
}
还有其他可用的适配器,但这是最基本的适配器。
基本上只看一下developer website .这example也有点帮助,但开发者的网站还有很长的路要走。
如果您有任何问题,请告诉我。
跟进
he put createGroupList(). Looks like this was a function he commented out. What is this doing exactly?
他基本上是在创造 List
的 HashMaps
在该函数中并返回创建的对象。是的,你应该做类似的事情,它有助于让你的代码更简洁。
Also, these lists show up really tiny, anyway to make them bigger?
修改TextView
你有展示你的 child 和团体。添加填充到他们的 View
在他们的 xml
布局。只需调整 dp
.你可以增加 textSize
或者您可以添加 style
就像我在下面展示的那样。
<TextView
android:id="@+id/groupTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@android:style/TextAppearance.Medium"
android:paddingLeft="50dp"
android:paddingTop="25dp"
android:paddingBottom="25dp"/>
I want the parent group to be lists, but dont want the child group to be sublists, I want them to be a text box I can add text to (which I grab from the net). How do i make the children textboxes rather than lists.
您可能需要创建自己的 Adapter
对于那种情况。您将需要扩展 BaseExpandableListAdapter
.我可能是错的,可能有更简单的方法...但我不知道有一个。
额外跟进
Not sure what you mean. The text getting entered in the child list comes in at this line of code: child.put( "Sub Item", "test"). I can put the text I want where it says "test" but "test" comes up under every parent list.
你的 createChildList
需要返回 List<ArrayList<HashMap<String, String>>>
.
你的 createChildList
应该看起来像这样:
private List<ArrayList<HashMap<String, String>>> createChildList(int maxValue) {
ArrayList<ArrayList<HashMap<String, String>>> groupList =
new ArrayList<ArrayList<HashMap<String, String>>>();
for (int i = 0; i <= maxValue; i++) {
ArrayList<HashMap<String, String>> childList =
new ArrayList<HashMap<String, String>>();
for (int j = 0; j <= maxValue; j++) {
HashMap<String, String> map = new HashMap<String, String>();
map.put("Sub Item", "test: " + String.valueOf(j));
childList.add(map);
}
groupList.add(childList);
}
return groupList;
}
如果可行,请告诉我。
关于android - 如何在 Android 中通过单击按钮展开和隐藏 ScrollView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11441409/