deka
Dauergast
- 351
Ich entwickle aktuell eine Quiz-App und habe die ganze Zeit über den Code auf meinem Testgerät (LG G2, 5,2 Zoll) ausgeführt. Hier habe ich keine Probleme mit dem Layout (erstes Bild). Nun habe ich es mal auf meinem OnePlus 3T installiert, welches einen größeren Bildschirm hat (5,5 Zoll), und es sieht leider nicht so aus wie ich es möchte. Das sieht man auf dem zweiten Bild sehr gut. Die grünen Balken sind plötzlich viel zu dick und der Platz unten wird nicht richtig genutzt.
Ich verstehe jedoch nicht wo genau das Problem liegt. Habe mir auch bereits die offizielle Dokumentation von Google durchgelesen. Ich bin davon ausgegangen, dass wenn man "dp" verwendet, das Layout sich auch automatisch an das Gerät anpasst. Hier wird ja nur davon abgeraten "px" zu verwenden, was ich auch nicht mache.
Oder brauche ich etwa verschiedene Layout-Dateien für jede Größe? Das ist sowie ich verstanden habe nur für sehr große Geräte notwendig. Also zum Beispiel Tablets. Da ich Tablets ausgeschlossen habe, brauche ich das nicht.
So sieht die Layout-Datei der main Activity aus:
Und das ist die Layout-XML für die Sub-Items:
Hat einer eine Idee?
Ich verstehe jedoch nicht wo genau das Problem liegt. Habe mir auch bereits die offizielle Dokumentation von Google durchgelesen. Ich bin davon ausgegangen, dass wenn man "dp" verwendet, das Layout sich auch automatisch an das Gerät anpasst. Hier wird ja nur davon abgeraten "px" zu verwenden, was ich auch nicht mache.
Oder brauche ich etwa verschiedene Layout-Dateien für jede Größe? Das ist sowie ich verstanden habe nur für sehr große Geräte notwendig. Also zum Beispiel Tablets. Da ich Tablets ausgeschlossen habe, brauche ich das nicht.
So sieht die Layout-Datei der main Activity aus:
Code:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:fitsSystemWindows="true"
android:minHeight="?attr/actionBarSize"
android:padding="2dp"
app:titleMarginStart="20dp"
app:titleTextAppearance="@style/MyMaterialTheme.Base.TitleTextStyle"
app:titleTextColor="@color/textColorPrimary">
<TextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textColor="@android:color/white"
android:textStyle="bold|italic"/>
</android.support.v7.widget.Toolbar>
<!--android:columnWidth="160dp"-->
<GridView
android:id="@+id/grid_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:gravity="center"
android:horizontalSpacing="20dp"
android:numColumns="2"
android:stretchMode="columnWidth"
android:verticalSpacing="20dp"></GridView>
</LinearLayout>
Und das ist die Layout-XML für die Sub-Items:
Code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/item"
android:layout_width="300dp"
android:layout_height="100dp"
android:layout_gravity="center_horizontal"
android:background="#FFFFFFFF"
android:gravity="center_horizontal"
android:orientation="horizontal"
tools:context="de.dk.masterfitness.ActMain" >
<!-- PART I. -->
<!-- THIS IS THE BAR ON THE LEFT -->
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="2"
android:background="@android:color/holo_green_light" />
<!-- PART II. -->
<!-- THIS IS THE MIDDLE WITH TEXTS AND LINE -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="6"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_weight="2"
android:background="#FFFFFFFF"
android:orientation="horizontal" >
<!-- ViewGroup with texts -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
android:layout_weight="2"
android:background="#FFFFFFFF"
android:orientation="vertical" >
<!-- First is fitted with triangle -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="@+id/iv_training"
android:layout_width="20dp"
android:layout_height="20dp"
android:rotation="90.0"
android:src="@drawable/triangle" />
<TextView
android:id="@+id/tv_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/black"
android:textStyle="bold" />
</LinearLayout>
<TextView
android:id="@+id/tv_text"
android:layout_width="200dp"
android:layout_height="70dp"
android:paddingLeft="20dp"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
<!-- nothing more than single vertical line -->
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#F1999999" >
</View>
</LinearLayout>
</LinearLayout>
<!-- PART III. -->
<!-- BUTTON ON THE RIGHT -->
<TextView
android:layout_width="10dp"
android:layout_height="match_parent"
android:layout_weight="6"
android:gravity="center"
android:text=">"
android:textAlignment="gravity"
android:textColor="@android:color/holo_green_light"
android:textSize="40dp"
android:textStyle="bold" />
</LinearLayout>
Hat einer eine Idee?
Anhänge
Zuletzt bearbeitet: