Android界面 - 什么部件使用需求建议 [英] Android interface - need suggestions on what widgets to use
问题描述
我需要创建界面,看起来像秩序。所以,会有头数据,然后会出现的细节。我认为这是所有滚动屏幕。但我不知道什么是最好的方式来绑定细节。
I need to create interface that will look like "order". So, there will be header data and then there will be details. I see it as all scrollable screen. But I'm not sure what the best way to bind details.
我可以看到我怎么可以:
I can see how I can:
-
创建ListView和在第一排放头 - IMO UGLY code
Create ListView and put header in first row - IMO UGLY code.
创建ListActivity,顶部和下面的ListView放头 - 没有好或者因为头不会滚动
Create ListActivity, put header on top and ListView below - no good either since header won't scroll.
我不知道怎么做,但想法是创建主要布局,并把空的LinearLayout细节的地方应该是。然后创建另一个布局的细节(就像我的ListView中做)。但是,我将加载的细节和手动充气的儿童的,然后将其注入到我的LinearLayout中。
I'm not sure HOW to do it but idea is to create main layout and put empty LinearLayout where details should be. Then create another Layout for details (just like I do for ListView). But I would load details and inflate those childs manually and then inject them into my LinearLayout.
请问这项工作?你会如何做其他类似的东西?
Will that work? How else would you do something like that?
谢谢!
推荐答案
最简单的解决办法是同时添加的TextView
和的ListView
在 RelativeLayout的
。实际上,你可以替换 Textivew
任何查看
(包括 ViewGorup
),你需要。
The simplest solution would be to add both a TextView
and a ListView
inside a RelativeLayout
. You can actually replace the Textivew
with any View
(including a ViewGorup
) you need.
请参阅如何实现它在本教程:的http://developer.android.com/resources/tutorials/views/hello-relativelayout.html
See how to implement it in this tutorial: http://developer.android.com/resources/tutorials/views/hello-relativelayout.html
,并检查罗曼盖伊的职位之间有很好的比较的LinearLayout
和 RelativeLayout的
(和一般的善意的提醒)
and check also Romain Guy's posts for a nice comparison between LinearLayout
and RelativeLayout
(and good advise in general):
HTTP://android-developers.blogspot。 COM / 2009/02 / Android的布局技巧,1.HTML
的http://android-developers.blogspot.com/2009/02/android-layout-tricks-2-reusing-layouts.html
的http://android-developers.blogspot.com/2009/03/android-layout-tricks-3-optimize-with.html
这是一个(非常简单)的方式来创建可扩展的LinearLayout
。当然,不是按钮,你会添加一些有趣的内容...
This is a (very simplified) way to create an expandable LinearLayout
. Of course, instead of buttons, you will add some more interesting content...
- 文件
MyCustomControl.java
package com.aleadam.test;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
public class MyCustomControl extends LinearLayout {
Context context;
Button upper, lower;
TextView tv;
public MyCustomControl(Context context) {
super(context);
this.context = context;
expandLayout();
}
public MyCustomControl(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
expandLayout();
}
private void expandLayout() {
setOrientation (VERTICAL);
LayoutParams lp0 = new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
LayoutParams lp1 = new LayoutParams(
LayoutParams.WRAP_CONTENT, 40);
LayoutParams lp2 = new LayoutParams(
LayoutParams.WRAP_CONTENT, 200);
TextView tv = new TextView(context);
tv.setText("The title goes here");
upper = new Button(context);
upper.setText("Click to show the other button");
lower = new Button(context);
lower.setText("Click to hide this button");
lower.setVisibility(GONE);
upper.setOnClickListener(new OnClickListener () {
public void onClick (View v) {
lower.setVisibility(VISIBLE);
}
});
lower.setOnClickListener(new OnClickListener () {
public void onClick (View v) {
v.setVisibility(GONE);
}
});
this.addView(tv, lp0);
this.addView(upper, lp1);
this.addView(lower, lp2);
}
}
- 文件
Test.java
public class Test extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
inflateLayout();
}
public void inflateLayout() {
ScrollView scr = new ScrollView (this);
LinearLayout ll = new LinearLayout (this);
ll.setOrientation(LinearLayout.VERTICAL);
ll.addView (new MyCustomControl (this));
ll.addView (new MyCustomControl (this));
ll.addView (new MyCustomControl (this));
ll.addView (new MyCustomControl (this));
scr.addView(ll);
setContentView (scr);
}
}
这篇关于Android界面 - 什么部件使用需求建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!