Center Elemente der HorizontalScrollView, wenn nicht genug, um es scrollen

Ich habe ein Layout mit einem HorizontalScrollView mit einem LinearLayout für ein Menü, wo Sie den Inhalt aufgeblasen und mit dem Inhalt der DB. Dies funktioniert gut, jedoch, wenn gibt es nicht genügend Elemente, um die HSV Blättern Sie dies nicht, füllt die Breite des Bildschirms, der im Idealfall sollte zentriert sein. also
Aktuell:

| Element 1 Element 2                         | <- edge of screen

Statt:

|        Element 1            Element 2       | <- edge of screen

während noch in der Lage zu:

| Element 1 Element 2 Element 3 Element 4 Elem| <- edge of screen now scrolling

Den layout-XML:

<?xml version="1.0" encoding="utf-8"?>
<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" >

    <TextView 
         android:id="@+id/header"
         android:layout_width="fill_parent"
         android:layout_height="25dp" >
    </TextView>

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

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

        </LinearLayout>
    </ScrollView>

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

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

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

Mit den folgenden XML-Code wird aufgeblasen innerhalb footerLayout:

<?xml version="1.0" encoding="utf-8"?>

        <TextView
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/footer_content"
            android:textSize="18sp"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            android:text="FOOTER"
            android:singleLine="true" />
InformationsquelleAutor Alasdair | 2012-03-23
Schreibe einen Kommentar