I read about some ways, how to make a TextView
scrollable.
Here is my some code from my Fragment:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_handlungsleitfaden, container, false);
// 1. pass context and data to the custom adapter
adapter = new AdapterHandlungsleitfaden(getContext(), generateData());
// if extending Activity 2. Get ListView from activity_main.xml
final ListView listView = (ListView) view.findViewById(R.id.listview);
// 3. setListAdapter
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
models.add(new ListItemDataHandlungsleitfaden(R.drawable.uncheck,"" + counter + "." + value, "" + counter));
counter++;
Toast.makeText(getContext(), "ITEM WIRD ERWEITERT!", Toast.LENGTH_SHORT).show();
adapter.notifyDataSetChanged();
}
});
//initialize TextView - Title
TextView title = (TextView) view.findViewById(R.id.title_handlungsleitfaden);
title.setText("Das ist nur ein Test!");
//initialize TextView - Content
TextView textView = (TextView) view.findViewById(R.id.text_handlungsleitfaden);
textView.setText("HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!" +
"HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!" +
"HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!HALLO WELT!" +
"DU NE HAHA GENIAL!");
textView.setMovementMethod(new ScrollingMovementMethod());
return view;
}
As you can see, I used this method:
textView.setMovementMethod(new ScrollingMovementMethod());
on this way, I tried to make my TextView
scrollable.
Here is my xml-layout for the fragment:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
tools:context=".uiFragments.HandlungsleitfadenFragment">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="@+id/listview"
android:layout_height="wrap_content"
android:layout_width="250dp"/>
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:layout_marginLeft="260dp"
android:layout_marginBottom="50dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/title_handlungsleitfaden"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="false"
android:textStyle="bold"
android:typeface="sans" />
<TextView
android:id="@+id/text_handlungsleitfaden"
android:layout_width="wrap_content"
android:layout_height="200dp"
android:layout_marginRight="20dp"
android:background="@drawable/textview_border" />
<ImageView
android:id="@+id/bild_handlungsleitfaden"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_gravity="center_horizontal"
android:src="@drawable/homer"/>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<VideoView
android:id="@+id/video_handlungsleitfaden"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</FrameLayout>
</LinearLayout>
</ScrollView>
<Button
android:id="@+id/handlungsleitfaden_btn"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="7dp"
android:textAllCaps="false"
android:text="weiter" />
</RelativeLayout>
</FrameLayout>
I can scroll the display, but I can not scroll in the TextView..because, when I try to do it, I can only scroll my "whole" display" like the textbox, title, image and video. But I want a way, also to scroll this display like I can do now AND also the TextView
, which is inside the ScrollView
.
If someone can help me, I would be very happy!
Thanks in advice!