ScrollView的滚动高度不起作用

时间:2014-10-01 10:33:24

标签: android android-scrollview

我正在编写progrmicaly将LinearlayoutTextview添加到ScrollView。但我的ScrollView无法滚动到高度。

enter image description here

我的程序代码:

    if (cursor.moveToFirst()) {
        do {
            String last_ID = cursor.getString(cursor.getColumnIndex("lastId"));
            String smsBody = cursor.getString(cursor.getColumnIndex("smsBody"));
            String senderName = cursor.getString(cursor.getColumnIndex("senderName"));
            String date[] = cursor.getString(cursor.getColumnIndex("receiveDate")).split("/");
            CalendarTool ct =
                    new CalendarTool(
                            Integer.valueOf(date[0]),
                            Integer.valueOf(date[1]),
                            Integer.valueOf(date[2])
                    );

            String IranianDate = ct.getIranianDate();

            ScrollView SV =new ScrollView(this);

            LinearLayout ll = new LinearLayout(this);
            ll.setBackgroundColor(Color.parseColor("#f7cbad"));
            ll.setOrientation(LinearLayout.VERTICAL);

            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.FILL_PARENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT
            );
            params.setMargins(0, 0, 0, 10);
            ll.setLayoutParams(params);



            TextView TV_IranianDate = new TextView(this);
            TV_IranianDate.setText(IranianDate);
            TV_IranianDate.setTextColor(Color.parseColor("#ffffff"));
            TV_IranianDate.setLayoutParams(
                    new ViewGroup.LayoutParams
                            (ViewGroup.LayoutParams.FILL_PARENT,
                                    ViewGroup.LayoutParams.WRAP_CONTENT)
            );
            ll.addView(TV_IranianDate);

            TextView TV_smsBody = new TextView(this);
            TV_smsBody.setText(smsBody);
            TV_smsBody.setGravity(Gravity.RIGHT);
            TV_smsBody.setLayoutParams(
                    new ViewGroup.LayoutParams
                            (ViewGroup.LayoutParams.FILL_PARENT,
                                    ViewGroup.LayoutParams.WRAP_CONTENT)
            );
            TV_smsBody.setPadding(5, 5, 5, 5);

            ll.addView(TV_smsBody);

            TextView TV_spacer2 = new TextView(this);
            TV_spacer2.setBackgroundColor(Color.parseColor("#000000"));
            TV_spacer2.setLayoutParams(
                    new ViewGroup.LayoutParams
                            (ViewGroup.LayoutParams.FILL_PARENT,
                                    1)
            );

            ll.addView(TV_spacer2);

            SV.addView(ll);



            ((LinearLayout) linearLayout).addView(SV);

        } while (cursor.moveToNext());
    }

1 个答案:

答案 0 :(得分:0)

我猜问题是ScrollView对象。您应该使用Horizo​​ntalScrollView,例如:

HorizontalScrollView SV = new  HorizontalScrollView(this);

SV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT));

如API所述:

  • ScrollView仅支持垂直滚动。对于水平滚动,请使用Horizo​​ntalScrollView。