【发布时间】:2013-03-06 09:44:11
【问题描述】:
我需要以议程样式显示一些信息,因此我使用片段来显示不同日期的信息。每天都有一些专栏来展示房间。
我创建了结构,但是当我尝试放入信息时遇到了一些问题
agenda_child_tv - textview 我放置信息的地方
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text_child"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:clickable="true"
android:background="@drawable/back"
android:padding="3sp"/>
agenda_child_ll - 列
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="@dimen/agenda_aula_width"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/agenda_aula_title"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<LinearLayout
android:id="@+id/agenda_aula_esp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
议程日
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ScrollView
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/horizontal_fragment"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="@dimen/agenda_tv_width"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#BDBDBD" >
<TextView
android:layout_width="@dimen/agenda_tv_width"
android:layout_height="@dimen/agenda_tv_height"
android:text="9.00"
android:padding="@dimen/agenda_tv_padding"
android:textColor="@color/agenda_orario_color"
android:textSize="@dimen/agenda_tv_textsize" />
<!-- A lot of textview for the hours -->
</LinearLayout>
<!-- Here i put, dinamically, the colum for the room in each day -->
</LinearLayout>
</ScrollView>
</HorizontalScrollView>
议程
下面的代码不是很动态,但我写了一个简化的版本来告诉你我的问题
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.agenda_day, container, false);
LinearLayout dayLL = (LinearLayout) rootView.findViewById(R.id.horizontal_fragment);
//Retriving LL agenda_child_ll
LinearLayout aula = (LinearLayout) inflater.inflate(R.layout.agenda_child_ll, container, false);
//Setting the classroom name
TextView aulaName = (TextView) aula.findViewById(R.id.agenda_aula_title);
aulaName.setText("room A");
//Retriving LL agenda_aula_esp
LinearLayout roomLL = (LinearLayout) aula.findViewById(R.id.agenda_aula_esp);
//Retriving TV child
TextView child = (TextView) inflater.inflate(R.layout.agenda_child_tv, container, false);
child.setText("test");
//Adding child to the room
roomLL.addView(child);
//adding room to the day
dayLL.addView(aula);
//Creating the column for the classroom "room B"
LinearLayout aula2 = (LinearLayout) inflater.inflate(R.layout.agenda_child_ll, container, false);
TextView aulaName2 = (TextView) aula2.findViewById(R.id.agenda_aula_title);
aulaName2.setText("room B");
dayLL.addView(aula2);
}
这就是结果。 textview 子项未添加到布局中。 有人能帮我吗? :)
【问题讨论】:
-
我觉得您应该尝试将 gridview 与适配器一起使用,而不是您正在做的事情。适配器旨在非常有效地处理动态数据
-
谢谢。但我认为使用 gridwith 你只能垂直或水平滚动,不能同时滚动...我解决了这个问题,我更改了agenda_aula_title 中的 layout_height。
标签: android android-layout android-fragments android-viewpager