2017-10-27 6 views
-2

Gibt es eine Idee, die letzte Textansicht innerhalb einer LinearLayout innerhalb einer ScrollView anzuzeigen?So zeigen Sie die letzte Textansicht im linearen Layout an

Dies ist mein Code

<?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> 

TextView wird layout1 hinzugefügt werden, wenn die Daten empfangen. Also werde ich mehrere Textansichten in layout1 einmal fertig geladen haben. Allerdings zeige es die erste TextView dann muss ich nach unten scrollen, um die letzte TextView zu sehen. Irgendeine Idee, die letzte TextView anzuzeigen, wenn es fertig ist, zu laden?

Dies ist der Code, wie ich TextView hinzufügen, wenn Daten

erhalten
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

warum ** android: layout_weight = "20" ** –

+0

zu scroll @NileshRathod weil ich nur Tutorial folgen, um dies zu erstellen, noch nicht ändern. Aber ist es die Ursache, dass die letzte Textansicht nicht zuerst angezeigt wird? – phoon

+0

Ich denke, diese Antwort wird Ihnen helfen: gooler

Antwort

0

Diese Lösung für mich gearbeitet

final ScrollView scrollview = ((ScrollView) findViewById(R.id.scrollview)); 
scrollview.post(new Runnable() { 
    @Override 
    public void run() { 
     scrollview.fullScroll(ScrollView.FOCUS_DOWN); 
    } 
}); 
Verwandte Themen