编程添加(线性)布局内的视图(这是一个滚动型中) [英] Programmatically add Views inside a (Linear)Layout (that is inside a ScrollView)

查看:218
本文介绍了编程添加(线性)布局内的视图(这是一个滚动型中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,有些点击后,显示新闻内容的活动。我想在这方面的一个底部显示的意见,这是动态加载的异步任务。

I have an app that, after some clicking, shows activity with news contents. I want at a bottom of that to show comments, which are dynamically loaded in async task.

一种方法是使用ListView和自定义的ArrayAdapter,但是,我将不得不把一个的ListView里面滚动型,它是一个问题,即使我手动覆盖ListView的高度。它示出了一个列表项,和下一个的一部分。

One approach is to use ListView and custom ArrayAdapter, but, i would have to put ListView inside a ScrollView, and it is is a problem, even if i manually override ListView's height. It shows one list item, and one part of the following one.

另一种方法是定义的LinearLayout作为征求意见的持有者膨胀比在它自己的XML文件中定义的另一个LinearLayouts,填充它的内容,重视持有人的看法。它工作正常,从程序的角度,不同的是它下面推的消息内容的评论。这就像,它创建的内容,下面OD新闻(内容重叠它)。

The other approach is to define LinearLayout as a holder for comments, than inflate another LinearLayouts defined in it's own xml file, populate it's contents, attach to holder's view. It works fine, from program's point of view, except it pushes comments below contents of the news. It's like, it creates another scrollable view of comments underneath contents od news (contents overlap it).

是否有这样做是没有任何关系的任何其他方式做清单,或如何才能让其他的工作方式。

Is there any other way of doing this that has nothing to do with lists, or how can i make the other approach to work.

从持有新闻内容的XML布局相关code段是:

The relevant code snippet from xml layout that holds news contents is:

<LinearLayout> //global layout
    <LinearLayout>
        //views that hold title, date, content
    </LinearLayout>      

        <LinearLayout 
           android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/commentsHolder"
            android:orientation="vertical">

        <View 
            android:layout_width="fill_parent"
            android:layout_height="2dp"
            android:background="#ed1b24"/>
        <TextView 
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:text="KOMENTARI"
            android:layout_marginLeft="5dp"/>
        <View 
            android:layout_width="fill_parent"
            android:layout_height="1dp"
            android:background="#ed1b24"/>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:orientation="vertical"
            android:id="@+id/comments_holder_view"
            android:layout_weight="1">
        </LinearLayout>


    </LinearLayout>

</LinearLayout>

对应于一个评论

和code是:

and code that corresponds to one comment is:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/comments_holder_item"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp">

<TextView 
    android:id="@+id/comment_content"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/comments_back_details"
    android:text="Ovde ide tekst komentara, koji se, naravno, dinamicki dodaje."/>

<LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView 
        android:id="@+id/comment_author"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        style="@style/categoryStyle"
        />

    <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text=" | "
        style="@style/categoryStyle"
        />

    <TextView 
        android:id="@+id/comment_pubdate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        style="@style/categoryStyle"/>

</LinearLayout>

<LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="1dp"
    android:orientation="horizontal"
    android:layout_margin="5dp"
    android:background="#d1d1d1">
</LinearLayout>

非常感谢您的任何答复。这对我来说非常重要。

Thank you very much for any reply. This is quite important for me.

推荐答案

我不是很确定你是如何夸大你的注释,但这里是我会怎么做。

I am not very sure how you inflate your comments, but here is how I would do it.

声明的评论布局的LinearLayout ,并给它一个id,然后得到一个参考的LinearLayout

Declare the comments Layout as a LinearLayout and give it an id, and then get a reference to that LinearLayout :

LinearLayout commentsLayout=(LinearLayout)findViewById(R.id.commentsLayoutId);

,然后只需添加子查看来此布局:

commentsLayout.addView(newComment);

这篇关于编程添加(线性)布局内的视图(这是一个滚动型中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆