2017-10-27 4 views
-2

LinearLayoutの中の最後のテキストビューをScrollViewの内側に表示する方法はありますか?データを受信したとき最後のテキストビューを線形レイアウトで表示する方法

これは私のコード

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="com.example.qianonnphoon.tradeal.chat.ChatActivity" 
android:background="#ffffff" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
android:orientation="vertical"> 

<ScrollView 
android:layout_width="match_parent" 
android:layout_weight="1" 
android:layout_height="wrap_content" 
android:id="@+id/scrollView"> 

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

</LinearLayout> 
</ScrollView> 

<include 
layout="@layout/message_area" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:gravity="bottom" 
android:layout_marginTop="5dp"/> 
</LinearLayout> 

TextViewlayout1に追加されますされています。だから、一度ロードが完了したらlayout1に複数のテキストビューを表示します。しかし、それは最初のTextViewを表示し、最後にTextViewを見るためにスクロールする必要があります。最後にTextViewをロードすると、どのようなアイデアが表示されますか?

これは私がTextViewを追加する方法のコードデータを受信したとき

TextView textView = new TextView(ChatActivity.this); 
    textView.setText(message); 
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); 
    lp.setMargins(0, 0, 0, 10); 
    textView.setLayoutParams(lp); 

    if(type == 1) { 
     textView.setBackgroundResource(R.drawable.rounded_corner1); 
    } 
    else{ 
     textView.setBackgroundResource(R.drawable.rounded_corner2); 
    } 

    layout.addView(textView); 
    scrollView.fullScroll(View.FOCUS_DOWN); 
+0

理由**アンドロイド働いている: –

+0

@NileshRathodをscrollviewするlayout_weight = "20" **を私はちょうどこれを作成するチュートリアルに従っているので、まだ変更していない。しかし、それは最後のテキストビューを最初に表示しない原因ですか? – phoon

+0

私はこの答えがあなたを助けてくれると思います: gooler

答えて

0

このソリューションは、私にとって

final ScrollView scrollview = ((ScrollView) findViewById(R.id.scrollview)); 
scrollview.post(new Runnable() { 
    @Override 
    public void run() { 
     scrollview.fullScroll(ScrollView.FOCUS_DOWN); 
    } 
}); 
関連する問題