ich ziemlich neu bin, zu Android und xml Layouten. Ich habe versucht, eine App zu machen, und schon mit dem Programmier-Bit fertig. Ich stehe jedoch fest auf die Finalisierung des Layouts. Brauche wirklich eine Hand. Meine app soll wie folgt aussehen:Make Linear-Layout nicht den Bildschirm verlassen
ich den Bildschirm in 4 Linear Layouts geteilt habe, als ich in dem Bild nummeriert habe, wie unten gesehen:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.FirstVersion.android.cwd.Play"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@color/material_blue_grey_800">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnGoBack"
android:text="Go Back"
android:layout_weight="1"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Profile Information"
android:background="@color/accent_material_dark"
android:layout_weight="10" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/LDrawerAction"
android:text="Menu"
android:clickable="false"
android:layout_weight="1"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp" />
</LinearLayout>
//endregion
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/Section2"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/Section3"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="5sp"
android:textColor="@color/colorWhite"
android:background="#990000"
android:maxLines = "3"
android:scrollbars = "vertical"
android:id="@+id/txtSection3" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="15"
android:orientation="vertical"
android:baselineAligned="false">
<TableLayout
android:id="@+id/Section4"
android:layout_width="match_parent"
android:layout_weight="15"
android:layout_height="wrap_content">
</TableLayout>
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
Das Problem ist jetzt, dass, Der zweite Abschnitt ist programmgesteuert gefüllt und hat einen Zeilenbereich von 8 bis 14. Dies gilt auch für die Spalten. Jeder Block ist eine andere Taste, die mich mit diesem Code hinzufügen:
Lay= (LinearLayout)findViewById(R.id.Section2);
for (int row = 0; row < numberOfRows; row++)
{
LinearLayout Linearrow = new LinearLayout(this);
Linearrow.setOrientation(LinearLayout.HORIZONTAL);
for (int column = 0; column < numberOfColumns; column++)
{
View a = Chosen.blocks[row][column]; //This is a View the extend Button that has no layout properties defined
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT, 1.0f);
a.setLayoutParams(params);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
lp.weight = 1.0f;
Linearrow.addView(a, lp);
}
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
lp.weight = 1.0f;
Lay.addView(Linearrow, lp);
}
ich versucht habe sogar ein Tablelayout verwenden und ein kleines Bild als Hintergrund zuweisen, so dass es mit dem folgenden Code der Größe verändert bekommen konnte:
TL =(TableLayout)fa.findViewById(R.id.Section2);
for (int i = 0; i < numberOfRows; i++)
{
TableRow tableRow = new TableRow(c);
for(int j = 0; j < numberOfColumns; j++)
{
String s = T[(i * 10) + j];
Block b = new Block(c, s);
//int w = Math.round(c.getResources().getDisplayMetrics().density * 20);
//int h = Math.round(c.getResources().getDisplayMetrics().density * 80);
//b.setLayoutParams(new TableRow.LayoutParams(w, h, 2.0f));
b.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT, 1f));
b.setBackgroundResource(R.drawable.g_3);
tableRow.addView(b);
tableRow.setLayoutParams(new android.widget.LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 5f));
final Block fb = b;
}
TL.addView(tableRow);
}
wenn ich die app laufen, kann ich sehen, dass, wenn ich es auf einem großen Bildschirm Telefon öffnen, wird der Inhalt nicht sichtbar ist ganz (als ob die Höhe manuell einstellen der Layouts festgelegt ist), und da es nicht Scroll-fähig ist, Der Inhalt ist nicht sichtbar. Wie kann ich das Layout neu anordnen oder ändern, so dass es wie im Bild oben aussieht?
Für die Spalten der Tabelle Layout, können Sie die Stretch-Spalten finden Attribut nützlich –
Warum nicht Sie 'android.support.v7.widget.RecyclerView' für diesen dynamischen Inhalt? In einem anderen Fall fügen Sie ein Layout, das blättert nämlich 'android.support.v4.widget.NestedScrollView' als Elternteil' LinearLaout' mit Höhe und Breite wie 'match_parent'. – JavaGhost
@ cricket_007 Ich habe es bereits als eine Eigenschaft festgelegt und macht keinen Unterschied. – blu3f1rest0rm