Вопрос

Я хочу сделать, сделайте макет таким:

Заголовок

Свидание

Длинный текст с прокруткой

Навигационная планка придерживается дна

Ну, я все сделал, однако есть небольшая проблема с прокруткой. Я хочу только прокрутить текст. Название и дата должны быть придерживаться вершины, а навигационная полоса до нижней части деятельности. И да, это работает, но мой батончик перекрывает текст:/

Я пробовал все, есть одно решение, которое я нашел, установил фиксированную высоту для ScrollView, но это не будет хорошо работать на каждом устройстве, не так ли? Я, вероятно, мог бы сделать некоторые расчеты в коде, и на его изменении высоты, но я хотел бы остаться в XML.

У кого -нибудь есть предложения?

Вот мой XML -файл:

<?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>
Это было полезно?

Решение

Вот вещи, которые я изменил:

  • Перенос верхний макет внизу
  • Дал имя нижнего макета android:id="@+id/bottom_layout"
  • Дал верхнюю макет название android:id="@+id/top_layout" (Не обязательно только для ясности)
  • Теперь верхний макет будет иметь эти свойства:

    android:layout_above="@id/bottom_layout"

    android:layout_alignParentTop="true"

    Первый - сделать верхний макет, закрепленный над нижней частью. Вторым является выравнивание верхнего края верхнего макета к вершине родителя. Что в данном случае относится к.

  • Теперь нижний макет будет иметь эти свойства:

    android:layout_alignParentBottom="true"

    Он скажет, что нижний край нижнего макета сочетается с нижним краем родителя (который является RELATIVELAYOUT)

Ниже приведен полностью работающий макет:

<?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>

Другие советы

Вы пытались придать вес в схему свитка?

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

Перетащите нижний край Linearlayout (давайте назовем его L1), удерживая текст и выровняйте его до верхнего края линейной макета, удерживающего панель навигации (назовем его L2). Так что AbsoluteLayout.Above на L1 равен L2.

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

Как говорит Джонас, но чтобы дать вам еще много, убедитесь, что вы заполняете другие вещи.

<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>

Если вы не установите Mayout_weight, ScrollView фактически оттолкнет Navbar от нижней части экрана в этой конфигурации. Это как -то связано с тем, как зарезервировано пространство для макетов, я не совсем уверен, почему, но добавление веса задерживает резервирование до позже. Поскольку Scrollview заполняет родителя, но все еще является частью линейной макета, макет обязательно будет соответствовать вашей нижней навигации, и, в отличие от относительной компоновки, не будет перекрытия.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top