文本视图在异步调用时未滚动



我遇到了一个奇怪的"错误",只有当我从应用程序列表中打开应用程序或使用 android 后退按钮返回时,我才能看到文本滚动,但如果我在应用程序中使用自己的后退按钮或旋转屏幕,则看不到。以下是相关代码:

//this override the implemented method from asyncTask
@Override
public void processFinish(final Object output){
    //Here you will receive the result fired from async class
    //of onPostExecute(result) method.
   //some irrelevant code here
        LinearLayout mainRSSLayout = (LinearLayout) findViewById(R.id.main_rss_layout);
        RelativeLayout relativeLayoutFeed = createRSSFeed(output, i);

            //plug in
            linearLayoutFeedPair.addView(relativeLayoutFeed, linearLayoutFeedPairParam);
            linearLayoutFeedPair.addView(relativeLayoutFeed2, linearLayoutFeedPairParam);
            mainRSSLayout.addView(linearLayoutFeedPair);
        mainRSSLayout.addView(relativeLayoutFeed);
}

以及实际的程序化创建:

private RelativeLayout createRSSFeed(Object output, int i){
    int height = dpToPx(this, 200); 
    /** FEED FRAME */
    RelativeLayout relativeLayoutFeed = new RelativeLayout(this);
    RelativeLayout.LayoutParams relativeLayoutFeedParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, height);
    relativeLayoutFeed.setLayoutParams(relativeLayoutFeedParams);
    relativeLayoutFeed.setBackgroundColor(Color.GRAY);
    relativeLayoutFeed.setPadding(0, dpToPx(this, 3), 0, 0);
    //relativeLayoutFeed.setId(R.id.reservedRelativeLayoutRSSFeedId + i-1);
    relativeLayoutFeed.setId(R.id.reservedRelativeLayoutRSSFeedId);
    relativeLayoutFeed.setOnTouchListener(this);

    /** FEED TEXT FRAME */
    RelativeLayout relativeLayout_subText = new RelativeLayout(this);
    /** TITLE */
    TextView textViewTitle = new TextView(this);
    textViewTitle.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dpToPx(this, 30)));
    textViewTitle.setTextSize(TypedValue.COMPLEX_UNIT_PX, dpToPx(this, 24));

    // TITLE SCROLLING <- the problem?
        textViewTitle.setSingleLine(true);
        textViewTitle.setHorizontallyScrolling(true);
        textViewTitle.setMarqueeRepeatLimit(-1);
        textViewTitle.setEllipsize(TextUtils.TruncateAt.MARQUEE);
        textViewTitle.setFocusableInTouchMode(true);
        textViewTitle.setFocusable(true);
        textViewTitle.requestFocus();
        textViewTitle.setSelected(true); 

    textViewTitle.setTypeface(null, Typeface.BOLD);
    textViewTitle.setTextColor(Color.WHITE);
    textViewTitle.setPadding(dpToPx(this, 5), 0, dpToPx(this, 5), 0);
    textViewTitle.setText("Lorem Ipsum");
    textViewTitle.setText(fromHtml(((List<Entry>)output).get(i-1).title));
    /** BODY */
    TextView textViewBody = new TextView(this);
    textViewBody.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dpToPx(this, 30)));//50px
    //textViewBody.setTextSize(dpToPx(this, 5)); //10px
    textViewBody.setTextSize(TypedValue.COMPLEX_UNIT_PX, dpToPx(this, 12));
    textViewBody.setMaxLines(2);
    textViewBody.setTextColor(Color.WHITE);
    textViewBody.setPadding(dpToPx(this, 3), 0, dpToPx(this, 3), 0);
    textViewBody.setText("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.");
    textViewBody.setText(fromHtml(((List<Entry>)output).get(i-1).description));

    linearLayout_subText.addView(textViewTitle);
    linearLayout_subText.addView(textViewBody);

    return relativeLayoutFeed;
}
显然,

如果您在执行异步任务之前不调用"onStart()",它可以工作,因此我通过以下方式解决了该问题:

public void onStart () {
    SystemClock.sleep(1000);
    super.onStart();

    System.out.println("on start");
}

最新更新