【发布时间】:2014-11-18 00:32:51
【问题描述】:
我的活动中有以下布局
<HorizontalScrollView
android:id="@+id/horizontalScrollView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/topHeading"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal|center_vertical">
<LinearLayout
android:id="@+id/scrollViewlinearlayout"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="horizontal">
<!--
Content will be dynamically added to this portion.
-->
</LinearLayout>
</HorizontalScrollView>
在我的活动代码中,我膨胀了一个视图并添加到上面的布局中
LinearLayout scrollViewLinearLayout=(LinearLayout)root.findViewById(R.id.scrollViewlinearlayout);
for(int i=0;i<10;i++){
View view =inflater.inflate(R.layout.lesson_row,null,false);
Button b1=(Button) view.findViewById(R.id.button);
b1.setOnClickListener(this);
scrollViewLinearLayout.addView(view);
}
现在这工作正常。我的滚动视图布局中有 10 个布局。现在R.layout.lesson_row 包含我想点击的按钮。我可以轻松地向按钮添加点击监听器,但是点击了 10 个布局中的哪个按钮?
【问题讨论】:
-
或者只使用 ListView 代替 ....
-
它是水平布局。
-
新的 RecyclerView 和 LinearLayoutManager 的方向如何:水平
标签: android