2016-03-20 5 views
0

ich Zentrierung richtig, wie Sie sehen können, wenn Sie das content_main.xml Design RegisterkarteBei der vertikalen Zentrierung, wie wird die Aktionsleiste berücksichtigt?

content_main.xml

jedoch sehen, wenn man sich activity_main.xml Design mit der Aktionsleiste an Ort und Stelle, während sie ist immer noch in der App zentriert, es ist nicht in den Whitespace zentriert, was ich bevorzugen würde. Irgendwelche Vorschläge, wie die Aktionsleiste zu berücksichtigen ist? Vorzugsweise in der XML wenn möglich.

activity_main.xml

Hier ist meine XML

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       xmlns:app="http://schemas.android.com/apk/res-auto" 
       xmlns:tools="http://schemas.android.com/tools" 
       android:id="@+id/voting_layout" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:paddingBottom="@dimen/activity_vertical_margin" 
       android:paddingLeft="@dimen/activity_horizontal_margin" 
       android:paddingRight="@dimen/activity_horizontal_margin" 
       android:paddingTop="@dimen/activity_vertical_margin" 
       android:orientation="vertical" 
       android:layout_gravity="fill_vertical|center" 
       android:configChanges="orientation|screenSize" 
       android:screenOrientation="nosensor" 
       tools:context="com.gesslar.threshvote.MainActivity" 
       android:background="@color/colorFaded" 
       app:layout_behavior="@string/appbar_scrolling_view_behavior" 
       tools:showIn="@layout/activity_main"> 

     <TextView android:id="@+id/textStatusMessage" 
        android:textColor="@color/colorText" 
        android:textAppearance="?android:attr/textAppearanceLarge" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:gravity="center" /> 

     <ImageButton android:id="@+id/buttonVote" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:clickable="false" 
        android:src="@drawable/ic_vote_button_image" 
        android:paddingBottom="@dimen/activity_vertical_margin" 
        android:paddingLeft="@dimen/activity_horizontal_margin" 
        android:paddingRight="@dimen/activity_horizontal_margin" 
        android:paddingTop="@dimen/activity_vertical_margin" 
        android:background="@android:color/transparent" 
        android:scaleType="fitCenter" 
        android:onClick="onVotePressed" 
        android:layout_gravity="center_horizontal|center_vertical" 
        android:adjustViewBounds="true" 
        android:contentDescription="@string/desc_vote_button" /> 

     <TextSwitcher android:id="@+id/textCountdown" 
         android:gravity="center" 
         android:layout_gravity="center_horizontal" 
         android:textColor="@color/colorText" 
         android:textAppearance="?android:attr/textAppearanceLarge" 
         android:textSize="@dimen/countdown" 
         android:includeFontPadding="false" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" /> 

     <ProgressBar android:id="@+id/loadingBar" 
        style="@style/Widget.AppCompat.ProgressBar" 
        android:layout_gravity="end" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:visibility="invisible" 
        android:indeterminate="true"/> 
    </LinearLayout> 

Antwort

0

Das xml für mich gearbeitet:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/voting_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_gravity="fill_vertical|center" 
    android:background="@color/colorFaded" 
    android:configChanges="orientation|screenSize" 
    android:orientation="vertical" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:screenOrientation="nosensor" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context="com.gesslar.threshvote.MainActivity" 
    tools:showIn="@layout/activity_main"> 

    <TextView 
     android:id="@+id/textStatusMessage" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:textColor="@color/colorText" /> 

    <ImageButton 
     android:id="@+id/buttonVote" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:adjustViewBounds="true" 
     android:background="@android:color/transparent" 
     android:clickable="false" 
     android:contentDescription="@string/desc_vote_button" 
     android:onClick="onVotePressed" 
     android:paddingBottom="@dimen/activity_vertical_margin" 
     android:paddingLeft="@dimen/activity_horizontal_margin" 
     android:paddingRight="@dimen/activity_horizontal_margin" 
     android:paddingTop="@dimen/activity_vertical_margin" 
     android:scaleType="fitCenter" 
     android:src="@drawable/ic_vote_button_image" /> 

    <TextSwitcher 
     android:id="@+id/textCountdown" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@id/buttonVote" 
     android:layout_gravity="center_horizontal" 
     android:gravity="center" 
     android:includeFontPadding="false" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:textColor="@color/colorText" 
     android:textSize="@dimen/countdown" /> 

    <ProgressBar 
     android:id="@+id/loadingBar" 
     style="@style/Widget.AppCompat.ProgressBar" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@id/textCountdown" 
     android:layout_gravity="end" 
     android:indeterminate="true" 
     android:visibility="invisible" /> 
</RelativeLayout> 

Aber Sie müssen es auf dem Gerät oder Emulator ausgeführt werden. Android Studio Vorschau zeigt es falsch. Der Schlüssel Linie ist app:layout_behavior="@string/appbar_scrolling_view_behavior"

EDIT
Darüber hinaus müssen Sie RelativeLayout verwenden - es gute Zentrierung in Eltern unterstützt. In LinearLayout können Sie das Bild nur zentrieren, wenn Ihr ImageView Match_parent ist.

+0

Ich habe aktualisiert, um meine XML zu enthalten, die ich in erster Linie hätte tun sollen. Das tut mir leid. –

Verwandte Themen