2017-08-04 72 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