有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

在一个不工作的安卓系统中,java在另一个文本视图的右边膨胀文本视图

我试图在一个版面中膨胀一个版面,并在其中添加几个文本视图。为此,我为每个textview设置了一个标题的arrayList,还有一个与arrayList大小相同的textview数组。问题是,这段代码只会膨胀一个文本视图(arrayList中的最后一个)

 public void inflatePeriodGradeRightOf() {
    AcademicStatusController.getInstance(this);
    Log.d(TAG, "type="+instanceType+" id= "+instanceId);
    ArrayList<Item> periodsInfo = AcademicStatusController
            .getPeriodsInfo(instanceType, instanceId);

    RelativeLayout llDisplayData = (RelativeLayout) findViewById(R.id.help_relative_layout_for_periods);

    // Params to add some new rules
     RelativeLayout.LayoutParams relativeLayoutParams;
     relativeLayoutParams = new RelativeLayout.LayoutParams(
     RelativeLayout.LayoutParams.WRAP_CONTENT,
     RelativeLayout.LayoutParams.WRAP_CONTENT);
     TextView tvtxt;
     TextView[] textViews = new TextView[periodsInfo.size()];
     int i = 0;

    for (Item info : periodsInfo) {
        // Inflate the view of the period
        View customView = inflater.inflate(
                R.layout.activity_academic_status_period_layout, null);
        textViews[i] = new TextView(this);

        // Add the first textView and then add the others right of the last
        // one
        PeriodItem item = (PeriodItem) info;
        if (periodsInfo.get(0) == info) {
            // Set the text to the TextView.
            textViews[i].setText(item.getName());
            textViews[i].setId(i+1);
            llDisplayData.addView(customView);
        } else {
            // Set the text to the TextView.
            textViews[i].setText(item.getName())
            textViews[i].setId(i+1);
            relativeLayoutParams.addRule(RelativeLayout.RIGHT_OF, textViews[i-1].getId());
                textViews[i].setLayoutParams(relativeLayoutParams);
            llDisplayData.addView(customView, relativeLayoutParams);
        }

        i++;
    }
}

我要添加文本视图的“主”布局如下所示:

<?xml version="1.0" encoding="utf-8"?>
<安卓.support.v4.widget.DrawerLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
    安卓:id="@+id/drawer_layout"
    安卓:layout_width="match_parent"
    安卓:layout_height="match_parent" >

    <RelativeLayout
        xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
        安卓:id="@+id/carla123456"
        安卓:layout_width="match_parent"
        安卓:layout_height="match_parent" >

        <ImageView
            安卓:id="@+id/academic_status_banner"
            安卓:layout_width="wrap_content"
            安卓:layout_height="200dp"
            安卓:layout_alignParentLeft="true"
            安卓:layout_alignParentTop="true"
            安卓:scaleType="fitXY"
            安卓:src="@drawable/banner_team" />

        <TextView
            安卓:id="@+id/academic_status_average"
            安卓:layout_width="wrap_content"
            安卓:layout_height="wrap_content"
            安卓:layout_alignParentTop="true"
            安卓:layout_centerHorizontal="true"
            安卓:layout_marginBottom="50dp"
            安卓:layout_marginTop="20dp"
            安卓:background="@drawable/rounded_corner_blue"
            安卓:paddingBottom="5dp"
            安卓:paddingLeft="20dp"
            安卓:paddingRight="20dp"
            安卓:paddingTop="5dp"
            安卓:text="Promedio: ND"
            安卓:textAppearance="?安卓:attr/textAppearanceMedium"
            安卓:textColor="#FFF" />

        <TextView
            安卓:id="@+id/academic_status_subjects"
            安卓:layout_width="match_parent"
            安卓:layout_height="wrap_content"
            安卓:layout_alignParentLeft="true"
            安卓:layout_below="@+id/academic_status_banner"
            安卓:background="@color/akdemia_blue"
            安卓:gravity="center"
            安卓:paddingBottom="5dp"
            安卓:paddingTop="5dp"
            安卓:text="Materias"
            安卓:textAppearance="?安卓:attr/textAppearanceLarge"
            安卓:textColor="#FFF" />

        <ListView
            安卓:id="@+id/academic_status_subjects_list"
            安卓:layout_width="match_parent"
            安卓:layout_height="wrap_content"
            安卓:layout_alignParentLeft="true"
            安卓:layout_below="@+id/academic_status_subjects" >
        </ListView>

        <RelativeLayout
            安卓:id="@+id/help_relative_layout_for_periods"
            安卓:layout_width="wrap_content"
            安卓:layout_height="wrap_content"
            安卓:layout_marginTop="100dp"
            安卓:layout_centerHorizontal="true" >

        </RelativeLayout>
    </RelativeLayout>

    <FrameLayout
        安卓:id="@+id/content_frame"
        安卓:layout_width="match_parent"
        安卓:layout_height="match_parent" />
    <!-- The navigation drawer -->
    <!-- should not be larger than 320 to show content -->

    <ListView
        安卓:id="@+id/left_drawer"
        安卓:layout_width="280dp"
        安卓:layout_height="match_parent"
        安卓:layout_gravity="start"
        安卓:background="#111"
        安卓:choiceMode="singleChoice"
        安卓:divider="@安卓:color/transparent"
        安卓:dividerHeight="0dp" />

</安卓.support.v4.widget.DrawerLayout>

我想要达到的是这样的效果:

enter image description here

但我只能让它膨胀到arrayList中的最后一个元素

希望有人能帮我,提前谢谢


共 (0) 个答案