Java 如何在Android中创建这样的视图?

Java 如何在Android中创建这样的视图?,java,android,android-imageview,horizontalscrollview,Java,Android,Android Imageview,Horizontalscrollview,我想创建一个布局,如下图所示(注意红色圆圈) 我在horizontalScrollView的帮助下尝试了这一点,并制作了一个丑陋的视图,如下所示: 我想这看起来像上面的一个,我应该用什么,这样,我可以得到每个温度值之间的垂直条 另一件事是,是否可以在水平滚动视图中添加多个视图,因为我只添加了一个动态创建的ImageView,请参见我的图 以下是我迄今为止尝试过的代码: xml 爪哇 @覆盖 创建时受保护的void(Bundle savedInstanceState){ super.onC

我想创建一个布局,如下图所示(注意红色圆圈)

我在
horizontalScroll
View的帮助下尝试了这一点,并制作了一个丑陋的视图,如下所示:

我想这看起来像上面的一个,我应该用什么,这样,我可以得到每个温度值之间的垂直条

另一件事是,是否可以在水平滚动视图中添加多个视图,因为我只添加了一个动态创建的ImageView,请参见我的图

以下是我迄今为止尝试过的代码:

xml


爪哇

@覆盖
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.dynamic_视图);
动态创建视图(上下文);
}
私有void CreateViews动态(最终上下文){
//TODO自动生成的方法存根
LinearLayout rootLayout=(LinearLayout)findViewById(R.id.rootlinear);
对于(int i=0;i
您希望以水平形式显示项目列表。我可以说您的解决方案是水平滚动视图。访问此链接以演示水平列表视图:


取决于你的创造力!更多的自我练习将改善这一点。祝你好运,在这方面你能帮我吗。如果你知道任何链接,请粘贴在这里。thanks@Tarsem谢谢你祝我好运,水平滚动视图可以吗?你可以使用tabview/tabhost,因为tabhost不适合这里,请看图片,我需要每个块中的多个视图,tabhost只能容纳一个文本和一个图标,任何方式谢谢
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/world_map"
tools:context=".MainActivity" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/horizontalScrollView"
    android:layout_alignLeft="@+id/horizontalScrollView"
    android:text="Flags"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<HorizontalScrollView
    android:id="@+id/horizontalScrollView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_marginLeft="80dp"
    android:padding="0dp"
    android:scrollbars="none" >

    <LinearLayout
        android:id="@+id/rootlinear"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:padding="0dp" >
    </LinearLayout>
</HorizontalScrollView>
</RelativeLayout>
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.dynamic_views);
            createViewsDynamically(context);

}

private void createViewsDynamically(final Context context) {
    // TODO Auto-generated method stub

    LinearLayout rootLayout = (LinearLayout) findViewById(R.id.rootlinear);
    for (int i = 0; i < flags.length; i++) {

        ImageView img = new ImageView(context);
        img.setBackgroundResource(flags[i]);
        img.setLayoutParams(new ViewGroup.LayoutParams(80,90));

        img.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                Toast.makeText(context, "Test", duration).show();
            }
        });

        rootLayout.addView(img);

    }

}