滚动型的Andr​​oid使用的RelativeLayout [英] Android ScrollView with RelativeLayout

查看:170
本文介绍了滚动型的Andr​​oid使用的RelativeLayout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个RelativeLayout的,一个在另一个内的片段。这片段是一个选项卡中。我想,内部布局(layoutInternal)是滚动的,但有下列code不起作用。我创建视图对​​象插入到layoutInternal dinamically。哪里是我的错?

I have a fragment with two RelativeLayout, one inside the other. This fragment is inside a tab. I want that the internal layout(layoutInternal) is scrollable, but with the following code does not work. I create the view object into the layoutInternal dinamically. Where is my mistake?

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layoutExsternal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

     <ScrollView 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:fillViewport="true" 
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginBottom="@dimen/fragmentHall_10dp_margin"
        android:layout_marginTop="@dimen/fragmentHall_10dp_margin">

        <RelativeLayout
            android:id="@+id/layoutInternal"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">

        </RelativeLayout>

    </ScrollView>   
</RelativeLayout>

以下code是我插入intenalLayout内的视图对象(表)。

The following code is where i insert the view object (table) inside the intenalLayout.

    while (iteratorTables.hasNext()) {
        [...] //Here i calculate the dimension and coordinates
        b_table = new ButtonTable(SelzApplication.getAppContext(),tableMap.getValue(), widthTable, heightTable);

        b_table.setX(Math.round((tableMap.getValue().getX())* Xratio));
        b_table.setY(Math.round((tableMap.getValue().getY())* Yratio));

        //add Touch Listeners to the button
        b_table.setOnLongClickListener(new OnLongTuchDragDrop());   
        b_table.setOnClickListener(new TableOnClick()); 


        layoutInternal.addView(b_table, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    }

这是我的应用程序的屏幕截图。

This is the screenshot of my app.

推荐答案

RelativeLayout的layoutInternal 的高度最初设置为的android:layout_height = WRAP_CONTENT但由于是动态创建的内容其内容最初是空的;这个原因是不滚动的。

The RelativeLayout layoutInternal has the height initially set as android:layout_height="wrap_content" but its content is initially empty because the content is created dynamically; for this reason is not scrollable.

要解决这个问题,当你完成的表格绘制到 RelativeLayout的layoutInternal ,你必须如下动态设置它的高度:

To solve this, when you finish to draw the tables into RelativeLayout layoutInternal, you have to set its height dynamically as below:

    FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) layoutInternal.getLayoutParams();
    params.height =  max_y_coordinate_used;
    layoutInternal.setLayoutParams(params);

这篇关于滚动型的Andr​​oid使用的RelativeLayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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