ScrollView scrollt nicht

  • Antworten:11
Gelöschter Account
  • Forum-Beiträge: 136

22.02.2011, 16:45:54 via Website

Hallo zusammen,

habe jetzt noch eine neue Frage, die mich echt schon nervt. Habe meine TextViews, die ausgegeben werden, ich kann aber net scrollen. Habe um das LinearLayout dann ein ScrollView gelegt doch er scrollt nicht. Habe es dann mit Relative versucht, den ScrollView woanders hingesetzt aber nichts funktioniert.

Woran liegt das?

Meine TextView erstelle und befülle ich in der Activity z.B. so:

[code]name[i] = new TextView(this);
name[i].setText(sitesList.getName().get(i));
name[i].setTextColor(Color.rgb(79, 166, 218));
name[i].setTextSize(12);
name[i].setTypeface(null,Typeface.BOLD);[/code]

Das ganze ist nen Array, deswegen kann ich die Anzahl an textviews in der .xml nicht festsetzen, da es sein kann, dass es mal mehr wird.

Hier die xml:

1<?xml version="1.0" encoding="utf-8"?>
2<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
3 android:orientation="vertical"
4 android:layout_width="fill_parent"
5 android:layout_height="fill_parent"
6 >
7<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
8 android:orientation="vertical"
9 android:layout_width="fill_parent"
10 android:layout_height="fill_parent"
11 >
12<TextView
13 android:layout_width="fill_parent"
14 android:layout_height="wrap_content"
15 android:text="@string/hello"
16 />
17<TextView
18 android:layout_width="fill_parent"
19 android:layout_height="wrap_content"
20 android:id="@+id/button"
21 />
22<ListView
23 android:id="@+id/clickview"
24 android:layout_width="wrap_content"
25 android:layout_height="wrap_content" />
26<WebView xmlns:android="http://schemas.android.com/apk/res/android"
27 android:id="@+id/webview"
28 android:layout_width="fill_parent"
29 android:layout_height="fill_parent"
30/>
31</LinearLayout>
32</ScrollView>


Grüße,
malte

— geändert am 22.02.2011, 17:06:24

Antworten
Mac Systems
  • Forum-Beiträge: 1.727

22.02.2011, 17:34:06 via Website

schreibe beim Scrollview: android:layout_height="wrap_content"

Windmate HD, See you @ IO 14 , Worked on Wundercar, Glass V3, LG G Watch, Moto 360, Android TV

Antworten
Markus Gu
  • Forum-Beiträge: 2.644

22.02.2011, 18:19:20 via App

eine listview in einer scrollview geht nicht. scrollt ja schon von selbst.

ueberdenke dein layout nochmal

swordiApps Blog - Website

Antworten
Gelöschter Account
  • Forum-Beiträge: 136

22.02.2011, 20:39:48 via Website

Hallo,

@Markus: Ja, dass stimmt, dass des quatsch ist, hatte vergessen den zu entfernen. Hat leider aber auch nichts gebracht, genauso, wie "wrap_content". Jemand noch eine Idee?


Grüße,
Malte

Antworten
Gelöschter Account
  • Forum-Beiträge: 136

22.02.2011, 21:47:41 via Website

Ich poste nochmal den kompletten Quellcode:

[code]package com.androidpeople.xml.parsing;

import java.net.URL;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ScrollView;
import android.widget.TextView;

public class XMLParsingExample extends Activity {

/** Create Object For SiteList Class */
SitesList sitesList;
WebView mWebView;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mWebView = (WebView) findViewById(R.id.webview);

/** Create a new layout to display the view */
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(1);

/** Create a new textview array to display the results */
TextView name[];
TextView website[];
TextView datum[];
TextView beschreibung[];

try {

/** Handling XML */
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();

/** Send URL to parse XML Tags */
URL sourceUrl = new URL("http://www.malte-heyenga.de/test.xml");

/** Create handler to handle XML Tags ( extends DefaultHandler ) */
MyXMLHandler myXMLHandler = new MyXMLHandler();
xr.setContentHandler(myXMLHandler);
xr.parse(new InputSource(sourceUrl.openStream()));


} catch (Exception e) {
System.out.println("XML Pasing Excpetion = " + e);
}

/** Get result from MyXMLHandler SitlesList Object */
sitesList = MyXMLHandler.sitesList;

/** Assign textview array lenght by arraylist size */
name = new TextView[sitesList.getName().size()];
website = new TextView[sitesList.getWebsite().size()];
datum = new TextView[sitesList.getDate().size()];
beschreibung = new TextView[sitesList.getDesc().size()];

/** Set the result text in textview and add it to layout */
for (int i = 1; i < sitesList.getName().size() && i < sitesList.getDate().size() && i < sitesList.getWebsite().size() && i < sitesList.getDesc().size(); i++) {
name[i] = new TextView(this);
name[i].setText(sitesList.getName().get(i));
name[i].setTextColor(Color.rgb(79, 166, 218));
name[i].setTextSize(12);
name[i].setTypeface(null,Typeface.BOLD);
name[i].setPadding(100,0,0,0);

datum[i] = new TextView(this);
datum[i].setText(sitesList.getDate().get(i));
datum[i].setTextColor(Color.rgb(8, 43, 73));
datum[i].setTextSize(11);
datum[i].setTypeface(null,Typeface.BOLD);
datum[i].setPadding(100,0,0,0);

beschreibung[i] = new TextView(this);
beschreibung[i].setText("Beschreibung = "+sitesList.getDesc().get(i));

website[i] = new TextView(this);
website[i].setBackgroundResource(R.drawable.link);
website[i].setLayoutParams(new LayoutParams(72,24));
final String url = sitesList.getWebsite().get(i);
website[i].setOnClickListener(new OnClickListener(){
public void onClick(View v){
Intent browser = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(browser);
}
});

layout.addView(name[i]);
layout.addView(datum[i]);
//layout.addView(beschreibung[i]);
layout.addView(website[i]);
//layout.addView(bla);
}
/** Set the layout view to display */
setContentView(layout);
}

}[/code]

Antworten
Rafael K.
  • Forum-Beiträge: 2.359

23.02.2011, 08:33:34 via Website

ich pick mal 3 Zeilen raus:

1setContentView(R.layout.main);
2...
3LinearLayout layout = new LinearLayout(this);
4...
5setContentView(layout);

Und jetzt die Preisfrage: Warum wird wohl nicht das Layout aus der XML verwendet?

— geändert am 23.02.2011, 08:33:55

Gelöschter Account

Antworten
Bastian B
  • Forum-Beiträge: 47

23.02.2011, 11:29:43 via Website

Rafael K.

Und jetzt die Preisfrage: Warum wird wohl nicht das Layout aus der XML verwendet?

Herrlich, wie User-Bild und Kommentare zusammenpassen! :D Freut mich immer wieder Beiträge von dir zu lesen!


@Malte:
Da du sicher dein Layout aus der xml verwenden willst, lass das letzte setContentView(layout); weg und schreib dafür: findViewById(deinScrollViewAusDerXml).add(layout);

Dem ScrollView im XML-File musst du natürlich noch eine ID zuweisen...

Gelöschter Account

Antworten
Rafael K.
  • Forum-Beiträge: 2.359

23.02.2011, 12:41:42 via Website

Bastian B
Rafael K.

Und jetzt die Preisfrage: Warum wird wohl nicht das Layout aus der XML verwendet?

Herrlich, wie User-Bild und Kommentare zusammenpassen! :D
Das ist doch ne Webcam ;-)

@Malte:
Bastian hats schon völlig richtig erklärt.

Ein Frage bleibt noch:
Warum realisierst Du eine Liste variabler Länge manuell und nicht über einen ListView mit Adapter?

Antworten
Gelöschter Account
  • Forum-Beiträge: 136

23.02.2011, 18:41:02 via Website

Ich glaub ich bin zu blöd für die Welt -.-

Bekomme beim "add", "The method add(LinearLayout) is undefined for the type View".

Habe das "setContentView(layout);" durch "findViewById(R.id.scroll).add(layout);" ersetzt.

Google sagt mir leider auch nix passendes...Glaube ich.


Grüße,
Malte

— geändert am 23.02.2011, 18:43:28

Antworten
Markus Gu
  • Forum-Beiträge: 2.644

23.02.2011, 18:52:18 via Website

eine scrollview kann nur ein direktes child haben => linearlayout

edit: versuch mal addchild

— geändert am 23.02.2011, 18:52:30

swordiApps Blog - Website

Gelöschter Account

Antworten
Gelöschter Account
  • Forum-Beiträge: 136

23.02.2011, 18:59:48 via Website

Ging leider auch net, habs jetzt anders gemacht. Habe oben nen neuen ScrollView sv angelegt und unten dann:

sv.addView(layout);
setContentView(sv);

Das funktioniert :) Trotzdem vielen, vielen Dank. Unglaublich, wie hilfsbereit hier alle sind :)

Grüße,
Malte

Antworten
Dennis S.
  • Forum-Beiträge: 4

07.12.2011, 09:18:18 via Website

Hallo zusammen,

ich habe das Problem, dass das ScrollView innerhalb meines RelativeLayouts nicht scrollt. Ich habe keine Ahnung woran es liegen könnte.
Hier mal der Code:
1<?xml version="1.0" encoding="utf-8"?>
2<RelativeLayout
3 xmlns:android="http://schemas.android.com/apk/res/android"
4 android:layout_height="wrap_content"
5 android:layout_width="wrap_content">
6 <LinearLayout
7 android:orientation="vertical"
8 android:gravity="center_vertical"
9 android:layout_width="match_parent"
10 android:layout_height="wrap_content">
11 <!-- Ueberschrift mit Abmessungsname und Icon ! -->
12 <LinearLayout
13 android:layout_width="match_parent"
14 android:layout_height="wrap_content"
15 android:baselineAligned="false">
16 <ImageView
17 android:src="@drawable/ribbon_96"
18 android:layout_width="wrap_content"
19 android:layout_height="wrap_content"
20 android:layout_marginRight="20dip"
21 android:layout_gravity="bottom">
22 </ImageView>
23 <TextView
24 android:id="@+id/textViewObjektnameAbmessung"
25 android:text="Stuhlbeintischkommode"
26 android:textSize="20sp"
27 android:layout_width="match_parent"
28 android:layout_height="wrap_content"
29 android:layout_gravity="center_vertical">
30 </TextView>
31 </LinearLayout>
32 <ScrollView
33 android:layout_height="wrap_content"
34 android:layout_width="fill_parent"
35 android:layout_marginLeft="40dip"
36 android:layout_marginRight="20dip"
37 android:layout_marginTop="10dip">
38 <LinearLayout
39 android:layout_height="wrap_content"
40 android:layout_width="match_parent"
41 android:orientation="vertical">
42 <!-- Länge der Abmessung -->
43 <LinearLayout
44 android:layout_height="fill_parent"
45 android:layout_width="match_parent"
46 android:layout_weight="1"
47 android:layout_marginTop="20dip">
48 <TextView
49 android:text="@string/TextViewAbmessungInfoLaenge"
50 android:textSize="28sp"
51 android:layout_height="wrap_content"
52 android:layout_weight="1"
53 android:layout_width="match_parent">
54 </TextView>
55 <TextView
56 android:id="@+id/textViewObjektnameAbmessung"
57 android:text="80"
58 android:textSize="28sp"
59 android:textStyle="bold"
60 android:layout_height="wrap_content"
61 android:layout_gravity="center_vertical"
62 android:layout_weight="1"
63 android:layout_width="match_parent">
64 </TextView>
65 </LinearLayout>
66 <!-- Breite der Abmessung ! -->
67 <LinearLayout
68 android:layout_height="wrap_content"
69 android:layout_width="match_parent"
70 android:orientation="horizontal"
71 android:layout_marginTop="20dip"
72 android:layout_weight="1">
73 <TextView
74 android:text="@string/TextViewAbmessungInfoBreite"
75 android:textSize="28sp"
76 android:layout_height="wrap_content"
77 android:layout_gravity="center_vertical"
78 android:layout_weight="1"
79 android:layout_width="match_parent">
80 </TextView>
81 <TextView
82 android:id="@+id/textViewObjektnameAbmessung"
83 android:text="120"
84 android:textSize="28sp"
85 android:textStyle="bold"
86 android:layout_gravity="center_vertical"
87 android:layout_weight="1"
88 android:layout_height="match_parent"
89 android:layout_width="match_parent">
90 </TextView>
91 </LinearLayout>
92 <!-- Typ der Abmessung ! -->
93 <LinearLayout
94 android:layout_height="wrap_content"
95 android:layout_marginTop="20dip"
96 android:layout_width="fill_parent"
97 android:layout_weight="1">
98 <TextView
99 android:text="@string/TextViewAbmessungInfoTyp"
100 android:textSize="28sp"
101 android:layout_height="wrap_content"
102 android:layout_gravity="center_vertical"
103 android:layout_weight="1"
104 android:layout_width="match_parent">
105 </TextView>
106 <TextView
107 android:id="@+id/textViewObjektnameAbmessung"
108 android:text="Furniture"
109 android:textSize="28sp"
110 android:textStyle="bold"
111 android:layout_gravity="center_vertical"
112 android:layout_height="wrap_content"
113 android:layout_weight="1"
114 android:layout_width="match_parent">
115 </TextView>
116 </LinearLayout>
117 </LinearLayout>
118 </ScrollView>
119 </LinearLayout>
120 <!-- Button-Layout -->
121 <RelativeLayout
122 android:layout_width="fill_parent"
123 android:layout_height="wrap_content"
124 android:layout_alignParentBottom="true" >
125 <LinearLayout
126 android:layout_width="fill_parent"
127 android:layout_height="wrap_content"
128 android:layout_weight="1" >
129 <ImageButton
130 android:src="@drawable/edit_64"
131 android:layout_height="wrap_content"
132 android:id="@+id/imageButtonBearbeiteAbmessung"
133 android:onClick="ButtonBearbeitenClickHandler"
134 android:layout_width="wrap_content"
135 android:layout_weight="1" >
136 </ImageButton>
137 <ImageButton
138 android:src="@drawable/cancel_64"
139 android:layout_height="wrap_content"
140 android:id="@+id/imageButtonAbmessungAbbrechen"
141 android:onClick="ButtonCancelClickHandler"
142 android:layout_width="wrap_content"
143 android:layout_weight="1">
144 </ImageButton>
145 </LinearLayout>
146 </RelativeLayout>
147</RelativeLayout>

Das Ziel ist es, wenn das Handy ins Querformat gedreht wird sollen die Elemente in einem ScrollView angezeigt werden damit sie nicht "verschluckt werden!

Ich würde mich freuen, wenn mir jemand helfen könnte.

VG
Dennis

Antworten