2017-07-16 91 views
0

這裏就是我想要做的事: goal的Android RelativeLayout的一個片段

我的代碼:

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <fragment 
     android:id="@+id/paf" 
     android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" /> 

    <Space 
     android:id="@+id/brightnessSeekBar" 
     android:layout_width="1dp" 
     android:layout_height="50dp" 
     android:layout_toLeftOf="@id/imageView" 
     android:layout_toRightOf="@id/paf" /> 

    <ImageView 
     android:id="@+id/imageView" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_alignParentRight="true" 
     android:clickable="true" 
     android:src="@drawable/localization" /> 

</RelativeLayout> 

的問題是,該片段充滿了一切與「match_parent」,但得到的小帶「WRAP_CONTENT」 我已經嘗試在Android官方指南顯示寬度= 「0dp」

+0

大小片段是50dp? –

+0

我不知道,沒關係 –

回答

0

試試這個

enter image description here

增加空間的layout_width如果你想他們之間更多的空間。

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 


    <ImageView 
     android:id="@+id/imageView" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     android:clickable="true" 
     android:src="@drawable/ic_android_black_24dp" /> 

    <Space 
     android:id="@+id/brightnessSeekBar" 
     android:layout_width="1dp" 
     android:layout_height="50dp" 
     android:layout_toLeftOf="@id/imageView" /> 

    <fragment 
     android:id="@+id/paf" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment" 
     android:layout_alignParentTop="true" 
     android:layout_toLeftOf="@id/brightnessSeekBar" 
     android:layout_alignBottom="@id/imageView" 
     android:layout_alignParentLeft="true" /> 

</RelativeLayout> 
0

這應該有效。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content"> 
<ImageView 
    android:id="@+id/imageView" 
    android:layout_width="50dp" 
    android:layout_height="50dp" 
    android:layout_alignParentRight="true" 
    android:clickable="true" 
    android:src="@mipmap/ic_launcher" /> 

<Space 
    android:id="@+id/brightnessSeekBar" 
    android:layout_width="1dp" 
    android:layout_height="50dp" 
    android:layout_toLeftOf="@id/imageView"/> 

<fragment 
    android:id="@+id/paf" 
    android:layout_width="match_parent" 
    android:layout_toLeftOf="@id/brightnessSeekBar" 
    android:layout_height="wrap_content" />