- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一个 Activity ,其中的事件按时间线组织。但它看起来很难看。
我想像这样设计一个更漂亮的时间线。
有没有像我的例子那样在元素之间画线的简单方法或库?
<ScrollView
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_below="@+id/text_data"
android:layout_above="@+id/button_trimite"
android:id="@+id/scroll_timeline"
android:layout_marginBottom="7dp"
>
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/timelineTable"
>
</TableLayout>
</ScrollView>
这是我的 xml。但是我的 TableLayout 是动态生成的,因为我需要对我的事件进行排序。
for (final Event e : events) {
if(e.getDate().equals(dataComp)) {
//tablerow with event entry
final TableRow row = new TableRow(getActivity());
row.setLayoutParams(new TableRow.LayoutParams(
TableRow.LayoutParams.MATCH_PARENT,
TableRow.LayoutParams.WRAP_CONTENT));
if (indexForDrawable % 2 == 0)
row.setBackgroundResource(R.drawable.marcaj_event_albastru);
else
row.setBackgroundResource(R.drawable.marcaj_event_portocaliu);
TextView txtEvent = new TextView(getActivity());
txtEvent.setText(" "+ e.getHour() +"-"+e.getType()+"-"+e.getTitle());
txtEvent.setTextColor(Color.BLACK);
txtEvent.setTextSize(TypedValue.COMPLEX_UNIT_DIP, trEvent);
txtEvent.setTypeface(Typeface.create(tf, Typeface.BOLD));
row.addView(txtEvent);
row.setClickable(true);
final String date = e.getDate(), hour = e.getHour(), title = e.getTitle(),
type = e.getType(), descriere = e.getDescriere();
final int finalResource = resource;
final int finalIndexForDrawable = indexForDrawable;
row.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
row.setBackground(getActivity().getResources().getDrawable(finalResource));
showPopup2(date, hour, type, title, descriere, row, finalIndexForDrawable);
}
});
timelineTable.addView(row, new TableLayout.LayoutParams(
TableLayout.LayoutParams.MATCH_PARENT,
TableLayout.LayoutParams.WRAP_CONTENT));
indexForDrawable++;
}
else {
//tablerow with date
final TableRow row = new TableRow(getActivity());
row.setLayoutParams(new TableRow.LayoutParams(
TableRow.LayoutParams.MATCH_PARENT,
TableRow.LayoutParams.WRAP_CONTENT));
TextView txtEvent = new TextView(getActivity());
//txtEvent.setText("\n"+ dataSplit1[0]+months.indexOf(dataSplit1 1 )); txtEvent.setText("\n"+ e.getDate().substring(0, 5)); txtEvent.setTextSize(TypedValue.COMPLEX_UNIT_DIP, trDate); row.addView(txtEvent); timelineTable.addView(row, new TableLayout.LayoutParams( TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT)); dataComp = e.getDate();
//tablerow with event entry
final TableRow row3 = new TableRow(getActivity());
row3.setLayoutParams(new TableRow.LayoutParams(
TableRow.LayoutParams.MATCH_PARENT,
TableRow.LayoutParams.WRAP_CONTENT));
if (indexForDrawable % 2 == 0)
row3.setBackgroundResource(R.drawable.marcaj_event_albastru);
else
row3.setBackgroundResource(R.drawable.marcaj_event_portocaliu);
TextView txtEvent3 = new TextView(getActivity());
txtEvent3.setText(" "+ e.getHour() +"-"+e.getType()+"-"+e.getTitle());
txtEvent3.setTextColor(Color.BLACK);
txtEvent3.setTextSize(TypedValue.COMPLEX_UNIT_DIP, trEvent);
txtEvent3.setTypeface(Typeface.create(tf, Typeface.BOLD));
row3.addView(txtEvent3);
row3.setClickable(true);
final String date3 = e.getDate(), hour3 = e.getHour(), title3 = e.getTitle(),
type3 = e.getType(), descriere3 = e.getDescriere();
timelineTable.addView(row3, new TableLayout.LayoutParams(
TableLayout.LayoutParams.MATCH_PARENT,
TableLayout.LayoutParams.WRAP_CONTENT));
indexForDrawable++;
}
最佳答案
您可能必须创建自己的自定义适配器,但我使用数组适配器供您引用。还为 ListView 提供项目布局,希望您能相应地管理您的代码。
items.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<View
android:layout_width="2dp"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:background="@android:color/black" />
<View
android:id="@+id/view1"
android:layout_width="7dp"
android:layout_height="7dp"
android:layout_centerVertical="true"
android:layout_marginLeft="7dp"
android:background="@drawable/dot" />
</RelativeLayout>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:padding="20dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
dot.xml 这是一个可绘制对象
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" >
<stroke
android:width="1dp"
android:color="@android:color/black" />
<solid android:color="@android:color/white" />
在 Activity 中你可以像这样使用适配器:
list.setAdapter(new ArrayAdapter<String>(this, R.layout.item, R.id.textView1, items));
希望这对您有所帮助!
关于android - 在 TableLayout Android 中的两个元素之间绘制自定义线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29625912/
我有2000条记录,我想在tablelayout中显示产品列表。第一次加载需要显示50条记录,其余记录需要分页显示。 在 onCreate() 中我完成了表格布局:它的动态表格内容 tl = (
已编辑:我自己找到了解决方案。谢谢! 我想为 Android 应用程序创建以下屏幕: 现在我有这个: 使用此代码:
我正在尝试做我的第一个复杂的 GUI,但现在我无法解决这个问题。 前两行的第一列只需要包含标签,而前两行的第二列必须占据剩余空间。 在此快照中,我注意到的问题是第一列比我想要的要大。 这是实现该布局的
当仅添加第一行时,一切顺利,但在添加第二行后,它失败了。 pupils=db.getAllPupilsPupil(); events=db.getAllEvents(); TableLayout ta
我想制作一款类似 Jeopardy 的游戏,为了实现这一目标,我决定使用 TableLayout 布局。这就是我的代码现在的样子: import javax.swing.JButton; import
我在 ListView 中使用 TableLayout。我提供的数据本质上是表格形式的,TableLayout 似乎是确保列按需要排列的好方法。这种方法在大多数情况下都很有效 - 见下文。 所需 Vi
我想发布一张图片来描述这个问题,但显然我在 stackoverflow 方面的声誉还不够,所以我将尝试描述我想要完成的事情。 我有一个包含 5 列的 TableLayout。它们由公司名称、职位编号、
我想实现一个带分页的 TableLayout,在第 1 页显示 10 条记录,然后在第 2 页显示下 10 条记录,依此类推...我正在使用 Table Layout但我没有得到所需的结果。使用本教程
我正在构建一个吉他应用程序。屏幕右侧是指板,左侧是几个按钮。 我用一个充满按钮的表格布局构建了吉他琴颈。没什么特别的。这工作得很好。不过我也想支持平板电脑。 吉他琴颈的宽度必须与每个设备保持一致,并且
在我现有的代码中,我有三个按钮,它们在同一行上水平对齐,但是,我希望这些按钮出现在不同的行上。 现有布局... [-----] [-----] [------] 追求布局... [------] [-
我的表格布局有点问题。 我有两列 专栏 1 |第 2 列 column1 内容是静态的,表示一个属性,例如“位置”,“产品”。第二列使用适配器填充。 我的问题是 TextView 打断了 column
我的目标是从数据库中获取数据,然后在我的应用程序中将其显示为表格。 这是我的代码: public void updateLastExpenses(){ Cursor c = Expense.
我一直在尝试基于 Google Play 商店中名为 Timetable 的应用程序创建一个应用程序。在过去的几天里,我一直在努力解决一个看似简单的问题。基本上,我使用 TableLayout 创建了
我正在努力寻找一种在 TableLayout 中添加和删除可点击按钮的好方法。 所以我目前有一个包含整数和对象的 HashMap。它也随着用户的需要而更新。当用户按下“添加项目”按钮时,我希望它完成向
请参阅下面的屏幕截图,了解平板电脑和手机上的不同结果。 Activity .xml
我有一个包含三列的 TableLayout,代表一个带有 的表单 必填符号 |标签 |输入框。 我希望输入字段填充屏幕右侧标签的剩余宽度。到目前为止,我找到的唯一解决方案是这个
我有一个类,其内容设置为具有几个按钮和一个 TableLayout 的布局。 制作 TableLayout 的真正工作是在一个单独的静态助手类中,它有一个返回所需表格的方法。 但是,表格没有显示。我错
我想在线程中创建一个动态表格布局(因为我有一个巨大的表格并且加载时间很长)。它似乎一直工作到第四行,但在出现错误之后。 我找不到问题出在哪里。在此 java 代码中,已简化表布局以解决问题。 我的ja
大家早上好 我在学习 Android 的道路上还面临着另一个问题。我用 CSV 文件的内容制作了一个动态 TableLayout。我需要当我点击/触摸表格中的一行时,颜色应该改变,然后点击一个按钮获取
是否可以并排显示两个 TableLayout(在 RelativeLayout 中)以使两个表格具有相同的宽度?我只是不知道该怎么做。我已经尝试过将 android:stretchColumns="*
我是一名优秀的程序员,十分优秀!