Frage

Was ich tun möchte, ist so Layout wie folgt zu machen:

Titel

Datum

Langer Text mit Scrollen

Navigationsleiste bleiben am Boden

Nun, ich habe alles getan, aber es gibt ein kleines Problem beim Scrollen. Ich möchte nur Text scrollen. Titel und Datum sollten an der Oberseite und Navigationsleiste bis zum Ende der Aktivität bleiben. Und ja, es funktioniert, aber meine Navigationsleiste überlappt Text:/

Ich habe alles ausprobiert, es gibt eine Lösung, die ich gefunden habe, die feste Höhe für Scrollview festgelegt hat, aber dies funktioniert nicht auf allen Geräten gut, nicht wahr? Ich könnte wahrscheinlich eine Berechnung im Code erstellen und ändern die Höhe, aber ich möchte in XML bleiben.

Hat jemand irgendwelche Vorschläge?

Hier ist meine XML -Datei:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.6"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/feed_title"
                style="@style/h1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center_vertical" />

            <TextView
                android:id="@+id/feed_info"
                style="@style/h2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
        </LinearLayout>

        <ImageView
            android:id="@+id/feed_fav_ico"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_alignParentRight="true"
            android:layout_gravity="center_vertical|right"
            android:background="@drawable/ic_fav_off" />
    </LinearLayout>


    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        android:scrollY="20dp" >

        <TextView
            android:id="@+id/feed_text"
            style="@style/text"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Loren ipsum full tekst" />
    </ScrollView>
</LinearLayout>

<!-- Buttons -->

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:background="#FFFFFF"
    android:orientation="vertical"
    android:paddingBottom="5dp" >

    <Button
        android:id="@+id/go_to_article"
        style="@style/button_screen"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="5dp"
        android:layout_marginTop="15dp"
        android:text="@string/feed_show_full" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/next_feed"
            style="@style/button_screen"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:background="@drawable/button_arrow_up" />

        <Button
            android:id="@+id/share_feed"
            style="@style/button_screen"
            android:layout_width="100dp"
            android:layout_height="40dp"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:text="@string/feed_share" />

        <Button
            android:id="@+id/delete_feed"
            style="@style/button_screen"
            android:layout_width="100dp"
            android:layout_height="40dp"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:text="@string/feed_delete" />

        <Button
            android:id="@+id/prev_feed"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:background="@drawable/button_arrow_down" />
    </LinearLayout>
</LinearLayout>
<!-- ~Buttons -->

</RelativeLayout>
War es hilfreich?

Lösung

Hier sind die Dinge, die ich verändert habe:

  • Bewegte sich obere Layout nach unten
  • Gab den unteren Layoutnamen android:id="@+id/bottom_layout"
  • Gab Top Layout einen Namen android:id="@+id/top_layout" (Nicht nur aus Klarheit notwendig)
  • Jetzt wird das obere Layout folgende Eigenschaften haben:

    android:layout_above="@id/bottom_layout"

    android:layout_alignParentTop="true"

    Das erste ist, das obere Layout oberhalb des unteren Layouts verankert zu machen. Zweitens besteht darin, die Oberkante des oberen Layouts auf das Oben des Elternteils auszurichten. Was in diesem Fall relativayout ist.

  • Jetzt wird das untere Layout folgende Eigenschaften haben:

    android:layout_alignParentBottom="true"

    Es wird feststellen, dass die untere Kante des unteren Layouts mit der unteren Kante des Elternteils übereinstimmt (was relATelayout ist)

Unten ist das voll funktionsfähige Layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<!-- Buttons -->

<LinearLayout
    android:id="@+id/bottom_layout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_alignParentBottom="true"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:background="#FFFFFF"
    android:orientation="vertical"
    android:paddingBottom="5dp" >

    <Button
        android:id="@+id/go_to_article"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="5dp"
        android:layout_marginTop="15dp"
        android:text="Feed full" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/next_feed"
            android:layout_width="40dp"
            android:layout_height="40dp" />

        <Button
            android:id="@+id/share_feed"
            android:layout_width="100dp"
            android:layout_height="40dp"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:text="share" />

        <Button
            android:id="@+id/delete_feed"
            android:layout_width="100dp"
            android:layout_height="40dp"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:text="delete" />

        <Button
            android:id="@+id/prev_feed"
            android:layout_width="40dp"
            android:layout_height="40dp" />
    </LinearLayout>
</LinearLayout>
<!-- ~Buttons -->

<LinearLayout
    android:id="@+id/top_layout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_above="@id/bottom_layout"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.6"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/feed_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center_vertical" />

            <TextView
                android:id="@+id/feed_info"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
        </LinearLayout>

        <ImageView
            android:id="@+id/feed_fav_ico"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_alignParentRight="true"
            android:layout_gravity="center_vertical|right"
            android:background="@drawable/ic_launcher" />
    </LinearLayout>

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:fillViewport="true"
        android:scrollY="20dp" >

        <TextView
            android:id="@+id/feed_text"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/long_test" />
    </ScrollView>
</LinearLayout>

</RelativeLayout>

Andere Tipps

Haben Sie versucht, das Scroll -Layout ein Gewicht zu setzen?

LinearLayout
- LinearLayout
-- Title
-- Date
- ScrollView layout_weigth=1
-- TextView
- LinearLayout
-- Button
-- Button
-- Button

Ziehen Sie die untere Kante des Linearlayouts (nennen Sie ihn L1) und richten Sie ihn an der oberen Kante des linearen Layouts aus, das Ihre Navigationsleiste hält (nennen wir es L2). So dass das Absolutelayout.above auf L1 gleich L2 ist.

<LinearLayout android:id="@+id/l1"
    android:layout_above="@+id/l2">
</LinearLayout>

Wie Jonas sagt, aber um Ihnen eine Klappe mehr zu geben, stellen Sie sicher, dass Sie die anderen Sachen ausfüllen.

<LinearLayout 
    android:layout_height="fill-parent">

    <LinearLayout 
       android:layout_height="wrap_content">
       put your title and things in here
    </LinearLayout>

    <ScrollView
       android:layout_height="fill_parent"
       android:layout_weight="1">  <!-- this makes it not overlap the layout(navbar) below-->
       put your title and things in here
    </ScrollView>

    <LinearLayout
       android:layout_height="wrap_content">
       put your nav bar stuff in here
    </LinearLayout>
</LinearLayout>

Wenn Sie das Layout_Weight nicht festlegen, drückt die ScrollView in dieser Konfiguration die Navigationsleiste tatsächlich von der Unterseite des Bildschirms aus. Es hat etwas damit zu tun, wie der Platz für Layouts reserviert ist. Ich bin mir nicht ganz sicher, warum, aber das Hinzufügen von Gewicht verzögert die Reservierung bis später. Da die Scrollview das übergeordnete, aber dennoch Teil des linearen Layouts ist, wird das Layout sichergestellt, dass Sie Ihre untere Achtereiste unterbringen, und im Gegensatz zum relativen Layout gibt es keine Überlappung.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top