xml-layout sieht in vers. Geräten ziemlich anders aus

B

BFK

Fortgeschrittenes Mitglied
11
Hallo,
Habe folgedes Problem. Das nachfolgende xml-layout sieht leider nich aus wie es sein sollte. Hier erstmal das xml (Sieht einfacher aus als es ist. Es ist eigentlich nur ein TableLayout mit 3 Zeilen. Das TableLayout hat davor und danach eine weisse Linie und jeder Row hat eine weisse Linier davor und danch, so dass sich am Ende ein Rechteck bildet)..:
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#778899"
    >
    
 <ScrollView 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    
  <LinearLayout
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:orientation="vertical"
      >
      
      <TextView
       android:text="General Data"            
       android:padding="3dip" 
       android:textSize="18dp"
       android:textColor="#000000"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_gravity="center_horizontal"
       android:id="@+id/gnd_txt"
       android:layout_marginTop="10dp"
       android:layout_marginBottom="-5dp"/>
  <LinearLayout
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:orientation="horizontal"
      >
      
   <TableLayout 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"   
    android:layout_marginRight="20dp"
    android:layout_marginLeft="20dp"
    android:background="#A2A1A1">

   
     <View
      android:layout_width="wrap_content"
      android:background="#C0C0C0"
      android:layout_height="2dp"/>
      
     <TableRow
         android:layout_marginBottom="-20dp">
     
       <View
         android:layout_width="2dp"
         android:background="#C0C0C0"
         android:layout_height="30dp"/>
         
        <TextView
            android:layout_column="1"            
            android:text="Data 1"            
            android:padding="3dip" 
            android:textSize="13dp"
            android:textColor="#FFFFFF"
            android:background="#937E62"
            android:includeFontPadding="false"
            android:layout_width="0dp"
            android:layout_weight="1"/>
        <TextView
            android:padding="3dip" 
            android:gravity="left"
            android:textSize="13dp"
            android:textColor="#000000"
            android:includeFontPadding="false"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:text="Value 1"/>
            
         <View
            android:layout_width="2dp"
            android:layout_height="30dp"
            android:background="#C0C0C0"
            android:layout_gravity="right"/>
      </TableRow>
                  
      <TableRow
          android:layout_marginBottom="-20dp">
      
        <View
            android:layout_width="2dp"
            android:layout_height="30dp"
            android:background="#C0C0C0"/>
            
        <TextView            
            android:layout_column="1"
            android:text="Data 2"
            android:padding="3dip" 
            android:textSize="13dp"
            android:background="#937E62"
            android:textColor="#FFFFFF"
            android:includeFontPadding="false"
            android:layout_width="0dp"
            android:layout_weight="1"/>
        <TextView
            android:padding="3dip" 
            android:gravity="left"
            android:textSize="13dp"
            android:textColor="#000000"
            android:includeFontPadding="false"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:text="Value 1"/>
            
         <View
            android:layout_width="2dp"
            android:layout_height="30dp"
            android:background="#C0C0C0"
            android:layout_gravity="right"/>
    </TableRow>
    
    <TableRow
        android:layout_marginBottom="-20dp">
    
        <View
            android:layout_width="2dp"
            android:layout_height="30dp"
            android:background="#C0C0C0"/>
        <TextView
            android:layout_column="1"
            android:text="Data 3"
            android:padding="3dip" 
            android:textSize="13dp"
            android:background="#937E62"
            android:textColor="#FFFFFF"
            android:includeFontPadding="false"
            android:layout_width="0dp"
            android:layout_weight="1"/>
        <TextView
            android:padding="3dip" 
            android:gravity="left"
            android:id="@+id/stat_moType"
            android:textSize="13dp"
            android:textColor="#000000"
            android:includeFontPadding="false"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:text="Value 1"/>
            
         <View
            android:layout_width="2dp"
            android:layout_height="30dp"
            android:background="#C0C0C0"
            android:layout_gravity="right"/>
    </TableRow>
    
    <View
      android:layout_width="wrap_content"
      android:background="#C0C0C0"
      android:layout_height="2dp"/>   
    
     </TableLayout>
    
    
    </LinearLayout>

  </LinearLayout>
 </ScrollView>
</LinearLayout>
Und hier noch zwei Fotos, es versteht sich von selbst welches das richtige sein soll.
Das komische ist, dass jeder Emulator es immer falsch anzeigt, aber leider auch echte Geräte.
Ich kann mir einfach nicht erklären wieso der Abstand zwischen den Rows so gross ist..!
 

Anhänge

  • screenshot_2012-03-27_1348.png
    screenshot_2012-03-27_1348.png
    1,9 KB · Aufrufe: 112
  • device.png
    device.png
    2,7 KB · Aufrufe: 122
meine anmerkungen dazu:

schriftgrößen werden in sp nicht in dp angegeben.

dein layout ist generell irgendwie viel zu kompliziert aufgebaut.

für was hast du ein linearlayout rund um dein tablellayout ? ist irgendwie schonmal unnötig

zwischen <tablelayout und <tablerow eine <view kommt mir irgendwie sehr komisch vor. die ist sicher auch unnötig.
 
swordi schrieb:
meine anmerkungen dazu:

schriftgrößen werden in sp nicht in dp angegeben.

dein layout ist generell irgendwie viel zu kompliziert aufgebaut.

für was hast du ein linearlayout rund um dein tablellayout ? ist irgendwie schonmal unnötig

zwischen <tablelayout und <tablerow eine <view kommt mir irgendwie sehr komisch vor. die ist sicher auch unnötig.

hi swordi,
ja ich weiss für das wenig design ist es zu kompliziert, aber ich habs nicht so mit den xmls.

Das LinearLayout ausserhalb des Tablelayouts sieht zwar unnötig aus, aber wenn ich das entferne, kommt folgendes dabei raus (bild).
Frag mich nicht wieso, ergibt keine Sinn, ich finde generell ergibt dass ganze Layout für mich keinen richtigen Sinn.

Das View zwischen TableLayout und TableRow ist überhaupt nicht unnötig, denn das macht die weisse Linie aus, die das TableLayout umkreist.

Naja eigentlich will ich einfach nur ein TableLayout mit zwei Spalten die genau 50-50 verteilt. Das TableLayout soll aber auch mit einer weissen Linie umkreist werden. (Das ist das grösste Problem und genau deshalb ist das so kompliziert geworden)

Wie soll ich deiner Meinung nach das anstellen..?
Ein View erweitern und bei onDraw eine weisse Linie zeichnen..?

Ich denke aber trotzdem, dass auch ohne der Linie nicht richtig klappt.
Wie gesagt , es soll wie im ersten Bild aussehen.

Ahh und wie erklärst du es dir, dass es bei einem Gerät klappt..?

Ich meine sowas hatte ich noch nie, dass die unterschiede so gewaltig sind.

Hoffe hab nicht zuviel gefragt..!
 

Anhänge

  • screenshot_2012-03-27_1424.png
    screenshot_2012-03-27_1424.png
    1,7 KB · Aufrufe: 102
Das kleine Bild sieht doch gar nicht so schlecht aus, mußt nur noch zentrieren und für breite fill_parent setzen, dann sollte es doch schon passen?
 
Tom299 schrieb:
Das kleine Bild sieht doch gar nicht so schlecht aus, mußt nur noch zentrieren und für breite fill_parent setzen, dann sollte es doch schon passen?

Nee leider sieht das auch nich immer gleich aus (bild).
Keine Ahnung wieso, aber das ganze Layout funkt nicht richtig.
Irgendeine Zusammenstellung will Android einfach nicht haben und interpretiert es verschieden.
Ich dachte ich habe irgendein Fehler gemacht, den man (Ihr) auf anhieb erkennen würdet (deshalb auch der Thread), aber wie es aussieht gibt es viele Fehler.
Ich meine, das ist doch nicht normal, dass ich ein wie swordi schon genannt hat unnötiges LineraLayout entferne, und das ganze ändert sich gewaltig.

Ich muss mir was ganz neues einfallen lassen.
 

Anhänge

  • device.png
    device.png
    2,3 KB · Aufrufe: 123
Code:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent">
    
	<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	    android:orientation="vertical"
	    android:layout_width="fill_parent"
	    android:layout_height="wrap_content"
	    android:background="#778899"
	    > 	    
	 	    
	    <TextView
	       	android:text="General Data"            
	       	android:padding="3dip" 
	       	android:textSize="18sp"
	       	android:textColor="#000000"
	       	android:layout_width="wrap_content"
	       	android:layout_height="wrap_content"
	       	android:layout_gravity="center_horizontal"
	       	android:id="@+id/gnd_txt"
	       	android:layout_marginTop="10dp"
	       	android:layout_marginBottom="0dp"
	   	/>
	
	    <View
			android:layout_width="fill_parent"
	      	android:background="#C0C0C0"
	      	android:layout_marginRight="20dp"
		    android:layout_marginLeft="20dp"
	      	android:layout_height="2dp"/>
	    
	   	<TableLayout 
		    android:layout_width="fill_parent"
		    android:layout_height="wrap_content"
		    android:orientation="horizontal"   
		    android:layout_marginRight="20dp"
		    android:layout_marginLeft="20dp"
		    android:background="#A2A1A1">
				      
			<TableRow
			    android:layout_width="fill_parent"
			    android:layout_height="wrap_content">
			    
		        <View
					android:layout_width="2dp"
			     	android:background="#C0C0C0"
			     	android:layout_height="fill_parent"
			     	android:layout_gravity="left"
	   			/>
			    
			   	<TextView
		            android:text="Data 1"            
		            android:padding="3dip" 
		            android:textSize="13dp"
		            android:textColor="#FFFFFF"
		            android:background="#937E62"
		            android:includeFontPadding="false"
		            android:layout_width="0dp"
		            android:layout_height="wrap_content"
		            android:layout_weight="1.0"
		            />
			   	
			   	<TextView
		            android:text="Value 1"            
		            android:padding="3dip" 
		            android:textSize="13dp"
		            android:textColor="#000000"
		            android:includeFontPadding="false"
		            android:layout_width="0dp"
		            android:layout_weight="1.0"
		            android:layout_height="wrap_content"
		            />
			   	
		   		 <View
					android:layout_width="2dp"
			     	android:background="#C0C0C0"
			     	android:layout_height="fill_parent"
			     	android:layout_gravity="right"
	   			/>
			   		        
		    </TableRow>
				    
		    <View
				android:layout_width="fill_parent"
		      	android:background="#C0C0C0"
		      	android:layout_height="1dp"
		      	/>
			
			<TableRow
			    android:layout_width="fill_parent"
			    android:layout_height="wrap_content">
			    
		        <View
					android:layout_width="2dp"
			     	android:background="#C0C0C0"
			     	android:layout_height="fill_parent"
			     	android:layout_gravity="left"
	   			/>
			    
			   	<TextView
		            android:text="Data 2"            
		            android:padding="3dip" 
		            android:textSize="13dp"
		            android:textColor="#FFFFFF"
		            android:background="#937E62"
		            android:includeFontPadding="false"
		            android:layout_width="0dp"
		            android:layout_height="wrap_content"
		            android:layout_weight="1.0"
		            />
			   	
			   	<TextView
		            android:text="Value 2"            
		            android:padding="3dip" 
		            android:textSize="13dp"
		            android:textColor="#000000"
		            android:includeFontPadding="false"
		            android:layout_width="0dp"
		            android:layout_weight="1.0"
		            android:layout_height="wrap_content"
		            />
			   	
		   		 <View
					android:layout_width="2dp"
			     	android:background="#C0C0C0"
			     	android:layout_height="fill_parent"
			     	android:layout_gravity="right"
	   			/>
			   		        
		    </TableRow>
		    
		    <View
				android:layout_width="fill_parent"
		      	android:background="#C0C0C0"
		      	android:layout_height="1dp"
		      	/>		
			
			<TableRow
			    android:layout_width="fill_parent"
			    android:layout_height="wrap_content">
			    
		        <View
					android:layout_width="2dp"
			     	android:background="#C0C0C0"
			     	android:layout_height="fill_parent"
			     	android:layout_gravity="left"
	   			/>
			    
			   	<TextView
		            android:text="Data 3"            
		            android:padding="3dip" 
		            android:textSize="13dp"
		            android:textColor="#FFFFFF"
		            android:background="#937E62"
		            android:includeFontPadding="false"
		            android:layout_width="0dp"
		            android:layout_height="wrap_content"
		            android:layout_weight="1.0"
		            />
			   	
			   	<TextView
		            android:text="Value 3"            
		            android:padding="3dip" 
		            android:textSize="13dp"
		            android:textColor="#000000"
		            android:includeFontPadding="false"
		            android:layout_width="0dp"
		            android:layout_weight="1.0"
		            android:layout_height="wrap_content"
		            />
			   	
		   		 <View
					android:layout_width="2dp"
			     	android:background="#C0C0C0"
			     	android:layout_height="fill_parent"
			     	android:layout_gravity="right"
	   			/>
			   		        
		    </TableRow>				
			
		</TableLayout>
		
	    <View
	   		android:layout_width="fill_parent"
	     	android:background="#C0C0C0"
	    	android:layout_marginRight="20dp"
		    android:layout_marginLeft="20dp"
	     	android:layout_height="2dp"
	   		/>
	</LinearLayout>     	
</ScrollView>
 
  • Danke
Reaktionen: BFK
Hey muss mich wieder mal bedanken..!

Das wichtigste war das TableLayout auf horizontal zu setzten oder nicht..?
(Auf das wäre ich nicht so schnell gekommen..!)

Und wie ich sehe, hast du alle "layout_margin" entfernt. Die hatte ich eigentlich nur benutzt, um die TableRows näher einanander zu bringen.
Ich denke aber ich belasse es so, aber nur so aus Neugier...wie hättest du es angestellt, wenn du kein Abstand zwischen den Rows haben wolltest..?
 
Ich hatte beim rumexperimentieren erst mal mögliche Fehlerquellen rausgeworfen und nach und nach erst wieder ein paar Attribute eingebaut.

Das wichtigste war bei den Views, welche die senkrechten Striche vorn und hinten zeichnen, die Höhe auf android:layout_height="fill_parent" zu setzen.

Wenn du weniger Abstand haben willst, kannst du die layout_margins ja wieder einbauen, sollte funktionieren.
 
Tom299 schrieb:
Ich hatte beim rumexperimentieren erst mal mögliche Fehlerquellen rausgeworfen und nach und nach erst wieder ein paar Attribute eingebaut.

Das wichtigste war bei den Views, welche die senkrechten Striche vorn und hinten zeichnen, die Höhe auf android:layout_height="fill_parent" zu setzen.

Wenn du weniger Abstand haben willst, kannst du die layout_margins ja wieder einbauen, sollte funktionieren.

Ahh ok und DANKE nochmals...!
 

Ähnliche Themen

R
  • Robby1950
2
Antworten
23
Aufrufe
1.007
Robby1950
R
D
Antworten
23
Aufrufe
2.515
Data2006
D
G
Antworten
8
Aufrufe
1.193
gnome2012
G
Zurück
Oben Unten