2017-08-04 69 views
0

我想在自定義縮放視圖的下方放置相對佈局。我不想讓相對佈局的內容獲得縮放。我想要一個按鈕放置在相對佈局的中心。在自定義縮放視圖下方的相對佈局中放置一個按鈕

這裏是我的XML:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:orientation="horizontal" 
android:background="@drawable/images"> 

<com.example.acer.myapplication.ZoomView 
    android:id="@+id/iop" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="center" 
    android:text="@string/twentyfive" /> 
</LinearLayout> 
+0

爲什麼要使用相對佈局和創建嵌套佈局?您可以簡單地將按鈕放在zoomView下方,因爲您是linearLayout –

回答

1
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical" 
android:background="@drawable/images"> 

<com.example.acer.myapplication.ZoomView 
    android:id="@+id/iop" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:gravity="center" 
    android:text="@string/twentyfive" /> 

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

     <Button 
      android:layout_centerInParent="true" 
      android:text="Button" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

</RelativeLayout> 


</LinearLayout> 

從來沒有測試的代碼,但希望它會奏效。

+0

謝謝。按我的想法工作。 – Devk

+0

歡迎您:) – AndroidGeek

1

試試這個 -

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical" 
android:background="@drawable/images"> 

<com.example.acer.myapplication.ZoomView 
    android:id="@+id/iop" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="center" 
    android:text="@string/twentyfive" /> 

    <RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 
    <Button 
     android:id="@+id/button" 
     android:layout_width="wrap_content" 
     android:layout_height="45dp" 
     android:layout_centerHorizontal="true"/> //Or use android:layout_centerInParent="true" 

</RelativeLayout> 

</LinearLayout> 
+0

將線性佈局的方向設置爲垂直,如果您需要相對佈局,則直接在其下方添加按鈕。 – hsm59

+0

按我的意願工作。感謝您的回覆。但必須在這裏和那裏進行更改。 – Devk

相關問題