2016-08-03 26 views
1

Ich möchte ein Framelayout unterhalb einer Ansicht ausrichten, bei der das Attribut centerInParent in einem relativen Layout auf true festgelegt ist. Ich habe versucht, layout_below, aber es funktioniert nicht. dann habe ich versucht, centerInParent zu entfernen und center_horizontal und center_vertical versucht, aber es hilft auch nicht, das FrameLayout immer noch an der Spitze des Layouts. Hier ist mein Layout-Code:Ausrichten einer unterhalb der übergeordneten Ansicht zentrierten Ansicht in einem relativen Layout

<android.support.percent.PercentRelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="?actionBarSize" 
      android:layout_marginTop="?actionBarSize" 
      android:background="@android:color/transparent"> 

      <ImageView 
       android:id="@+id/backdrop" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="@android:color/white" 
       android:fitsSystemWindows="true" 
       android:scaleType="centerCrop" 
       app:layout_collapseMode="parallax" 
       app:layout_collapseParallaxMultiplier="0" 
       tools:src="@drawable/car_engine" /> 

      <View 
       android:id="@+id/center_point" 
       android:layout_width="0dp" 
       android:layout_height="0dp" 
       android:layout_centerHorizontal="true" 
       android:layout_centerVertical="true" 
       android:background="@color/g" /> 

      <View 
       android:id="@+id/tab_scrim" 
       android:layout_width="match_parent" 
       android:layout_height="@dimen/gradiant_height" 
       android:layout_alignParentBottom="true" 
       android:background="@drawable/tab_scrim" 
       app:layout_heightPercent="40%" /> 

      <FrameLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@id/center_point"> 

       <TextView 
        android:id="@+id/car_title" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:paddingBottom="5dp" 
        android:paddingTop="2dp" 
        android:textAlignment="center" 
        android:textColor="@color/w" 
        android:textSize="20sp" 
        android:textStyle="bold" 
        tools:text="@string/car_header_text" /> 

       <TextView 
        android:id="@+id/car_subtitle" 
        style="@style/TitleWhite" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_below="@id/car_title" 
        android:paddingBottom="4dp" 
        android:paddingTop="4dp" 
        android:text="@string/car_sub_header" 
        android:textAlignment="center" /> 
      </FrameLayout> 
     </android.support.percent.PercentRelativeLayout> 
+0

Sie sollten die Höhe des PercentRelativeLayout ändern "match_parent" – sJy

Antwort

1

Stellen Sie Ihre PercentRelativeLayout Höhe match_parent match_parent werden müssen.

<android.support.percent.PercentRelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_marginBottom="?actionBarSize" 
    android:layout_marginTop="?actionBarSize" 
    android:background="@android:color/transparent"> 
+0

danke, das behebt das Problem. –

0

Bitte versuchen Sie dies.

<FrameLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      android:ali="@id/center_point"> 

      <TextView 
       android:id="@+id/car_title" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:paddingBottom="5dp" 
       android:paddingTop="2dp" 
       android:textAlignment="center" 
       android:textColor="@color/w" 
       android:textSize="20sp" 
       android:textStyle="bold" 
       tools:text="@string/car_header_text" /> 

      <TextView 
       android:id="@+id/car_subtitle" 
       style="@style/TitleWhite" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_below="@id/car_title" 
       android:paddingBottom="4dp" 
       android:paddingTop="4dp" 
       android:text="@string/car_sub_header" 
       android:textAlignment="center" /> 
     </FrameLayout> 
+0

@mohamed, PercentRelativeLayout Hat das geändert: android: layout_height = "match_parent" – mujjuraja

+0

ja, setting android: layout_height = "match_parent" hat das Problem behoben. vielen Dank. –

+0

okay. hast du dein Problem gelöst? – mujjuraja

0

Bitte überprüfen Sie, ob Sie falsch Android verwendet: ali

<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/center_point"> 

Und Ihre PercentRelativeLayout Höhe fixiert oder

0

Hier ist mein Code

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

<ImageView 
    android:id="@+id/backdrop" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@android:color/white" 
    android:fitsSystemWindows="true" 
    android:scaleType="centerCrop" 
    app:layout_collapseMode="parallax" 
    app:layout_collapseParallaxMultiplier="0" 
    tools:src="@mipmap/ic_launcher" /> 

<View 
    android:id="@+id/tab_scrim" 
    android:layout_width="match_parent" 
    android:layout_height="2dp" 
    android:layout_alignParentBottom="true" 
    android:background="@android:color/black" 
    app:layout_heightPercent="40%" /> 

<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="100dp" 
    android:background="@android:color/holo_red_dark" 
    android:layout_centerVertical="true"> 

    <TextView 
     android:id="@+id/car_title" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingBottom="5dp" 
     android:paddingTop="2dp" 
     android:textAlignment="center" 
     android:textColor="@android:color/black" 
     android:textSize="20sp" 
     android:textStyle="bold" 
     android:text="car carcar" 
     android:layout_gravity="left"/> 

    <TextView 
     android:id="@+id/car_subtitle" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/car_title" 
     android:paddingBottom="4dp" 
     android:paddingTop="4dp" 
     android:text="car header subtitle" 
     android:textAlignment="center" 
     android:layout_gravity="bottom"/> 
</FrameLayout> 

und screen shot red block is framelayout