Android - макет раздува двух элементов в одном xml - PullRequest
1 голос
/ 20 марта 2012

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

У меня есть LinearLayout, содержащий ScrollView и HorizontalScrollView, ScrollView содержит второй LinearLayout, который содержит TextView и ImageView, а HorizontalScrollView содержит третий LinearLayout, содержащий TextView.

Вот XML:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainLinearLayout"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ScrollView
        android:id="@+id/scroll1"
        android:layout_width="fill_parent"
        android:layout_height="442dp"
        android:layout_weight="1" >

        <LinearLayout
            android:id="@+id/contentLayout"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/contentText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="TextView" />

            <ImageView 
                android:id="@+id/image_content"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center" />

        </LinearLayout>
    </ScrollView>

    <HorizontalScrollView
        android:id="@+id/horizontalScrollView1"
         android:layout_width="fill_parent"
        android:layout_height="25dp"
        android:layout_gravity="bottom">"

    <LinearLayout
        android:id="@+id/footerLayout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="bottom"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/footer"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_gravity="bottom"
            android:paddingLeft="5dp"
            android:paddingRight="5dp" />

    </LinearLayout>
</HorizontalScrollView>
</LinearLayout>

У меня двойственная проблема.

  1. HorizontalScrollView должен быть внизу, вместо этого он немного вверх, я предполагаю из-за размеров высоты на ScrollView (Это должно занимать все пространство, за исключением 25dp, зарезервированных HorizontalScrollView.

  2. У меня проблемы с накачкой LinearLayouts в ScrollViews. У меня есть код:

    LayoutInflater inflater = (LayoutInflater)
        getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    LinearLayout layoutContent;
    LinearLayout lin = new LinearLayout(this);
    TextView content = null;
    
    //Content
    for (int i =0; i<6; i++) {
        layoutContent = (LinearLayout)inflater.inflate(R.layout.details_list, null);
        content = (TextView)layoutContent.findViewById(R.id.contentText);
        content.setText("MyContent" + String.valueOf(i));
        lin.addView(layoutContent);
    }
    this.setContentView(lin);
    
    //Footer
    lin = (LinearLayout) findViewById(R.id.footerLayout);
    content = null;
    for (int i =0; i<2; i++) {
        layoutContent = (LinearLayout)inflater.inflate(R.layout.details_list, null);
        content = (TextView)layoutContent.findViewById(R.id.footer);
        content.setText("Footer "+String.valueOf(i));
        lin.addView(layoutContent);
    }
    

что вызывает у меня проблемы: Поскольку макет контента объявлен как lin = new LinearLayout (this); это не использует тот из моего файла макета, например макет выглядит как

MyContent0             MyContent1MyContent2MyC
                                          onte
                                          nt3

  Footer 0    Footer 1

Если я увеличу количество элементов нижнего колонтитула, MyContent1 ... появится с правой стороны экрана, если я изменю его на lin = (LinearLayout) findViewById(R.id.contentLayout); Я должен удалить строку this.setContentView(lin);, но когда я это сделаю, раскладка будет выглядеть так:

TextView
MyContent0
--Lots of blank lines--
  Footer 0   Footer 1
MyContent1
--Lots of blank lines--
MyContent2
--Lots of blank lines--
MyContent3
--Lots of blank lines--
MyContent4
--Lots of blank lines--
MyContent5
--Lots of blank lines--

Если добавить дополнительные элементы в нижний колонтитул, они появляются в горизонтальной прокрутке, где нижний колонтитул 1 нижний колонтитул 2 находится выше, и правильно прокручивается с остальной частью содержимого ниже.

Большое спасибо, что нашли время, чтобы прочитать это, и, пожалуйста, дайте мне знать, если вам нужна дополнительная информация.

С уважением

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