2017-08-12 3 views
0

Ich habe eine MainActivity mit Navigationsschublade. Ich erstelle ein Fragment für jeden Artikel ist in meiner Nav-Schublade. Ich habe eine toolbar.xml, die in meiner content.xml enthalten ist, und ich möchte meine content.xml als Standardlayout für meine Fragmente festlegen. aber ich möchte es scrollbar machen, weil einige meiner Fragmente viele Text & Bilder haben! Ich verwende Scrollview in einem Relativayout in meinem Fragmentlayout, aber es funktioniert nicht.make ein fragment_layout scrollbar

das ist mein content.xml, dass ich es als Standard-Layout für Fragmente festlegen möchten:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:id="@+id/layout_for_fragment" 
android:layout_height="match_parent" 
android:background="#132740"> 

<include layout="@layout/toolbar" /> 

</RelativeLayout> 

und das ist mein IntroFragment.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@color/colorPrimary" 
tools:context="com.example.arsh.enc.IntroFragment"> 

<ScrollView 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 

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

    <TextView 
     android:id="@+id/textView5" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="20dp" 
     android:layout_marginLeft="20dp" 
     android:layout_marginRight="20dp" 
     android:layout_marginTop="20dp" 
     android:lineSpacingExtra="10sp" 
     android:text="VERY VERY 
VERY VERY 

VERY VERY 

VERY VERY 

VERY VERY LONG TEXT" 
android:textColor="#FFFFFF" /> 

</RelativeLayout> 
</ScrollView> 


</RelativeLayout> 

wie ich schon sagte, ich Verwenden Sie ScrollView, aber es gibt kein Ergebnis. Kann mir jemand sagen, wo ich falsch gelaufen bin? und was soll ich tun, um mein Problem zu lösen?

Antwort

0

Nehmen Scroll Höhe und Breite als match_parent ...

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 



</ScrollView> 
-2

dies mein Fragment .java- Klasse ---

public class scheduled extends Fragment { 
    private static final String TAG = "MainActivity"; 
    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) { 
     View rootView = inflater.inflate(R.layout.scheduled, container, false); 
     Log.d(TAG, "onCreate: Started."); 
     String []items={"apple","bat","cat","dog","apple","bat","cat","dog","apple","bat","cat","dog"}; 

     ListView lvdata=(ListView)rootView.findViewById(R.id.listview); 
     ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1,items); 
     lvdata.setAdapter(adapter); 

     return rootView; 
    } 
} 

Sie müssen nicht nichts extra hinzufügen, um es zu machen scrollbar. Fügen Sie einfach mehr Daten und das ist mein Fragment .xml-Datei ---

<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:id="@+id/constraintLayout" 
    android:layout_width="fill_parent" 
    android:gravity="center" 
    android:layout_height="match_parent"> 


    <ListView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_alignParentTop="true" 
     android:id="@+id/listview"/> 
</LinearLayout> 
+0

du hast recht es schon scrollbaren ist, aber es gibt keine Notwendigkeit zu verwenden Listview – godot