2013-04-17 28 views
5

Tôi đang gặp phải sự cố với nút hiển thị bên ngoài màn hình ở số RelativeLayout. ImageView không có hình ảnh tỷ lệ để hiển thị một nút hiển thị.Làm cách nào để tôi có thể phù hợp với RelativeLayout trên màn hình?

Những gì tôi có:

enter image description here

Những gì tôi muốn:

enter image description here

Code:

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

<TextView 
     android:id="@+id/textView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/str" 
     android:textAppearance="@android:style/TextAppearance.Small" 
     android:textColor="?android:attr/textColorTertiary" 
     android:layout_centerHorizontal="true" 
     /> 

<ru.mw.widget.DrawableImageView 
     android:id="@+id/imageView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/textView" 
     android:adjustViewBounds="true" 
     android:layout_centerHorizontal="true" 
     android:scaleType="centerCrop" 
     /> 

<Button 
     android:id="@+id/processButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/str" 
     android:layout_below="@+id/imageView" 
     android:layout_centerHorizontal="true" 
     /> 

Vấn đề khi tôi thay đổi hướng màn hình: Nếu tôi sử dụng Arun C Thomas's method trong chế độ phong cảnh mọi thứ đều ok, nhưng ở chế độ dọc Tôi có điều này (hình ảnh cắt bởi các cạnh trái/phải):

enter image description here gì được mong đợi:

enter image description here

+0

Thêm android: alignParentBottom để nút của bạn, và android: alignParentTop (cả = true) để TextView của mình. Bạn hiện không đặt bất kỳ giới hạn nào cho ImageView của mình. –

Trả lời

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

<TextView 
     android:id="@+id/textView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/str" 
     android:textColor="?android:attr/textColorTertiary" 
     android:textAppearance="@android:style/TextAppearance.Small" 

     android:layout_centerHorizontal="true" 
     /> 

<ru.mw.widget.DrawableImageView 
    android:id="@+id/imageView" 
    android:layout_width="wrap_content" 
    android:layout_height="0dp" 
    android:layout_below="@+id/textView" 
    android:layout_centerHorizontal="true" 
    android:adjustViewBounds="true" 
    android:scaleType="centerCrop" 
    android:layout_above="@+id/processButton" 
    /> 

<Button 
     android:id="@+id/processButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/str" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     /> 
</RelativeLayout> 

Đây là giải pháp

Bây giờ để đạt được Cập nhật yêu cầu thêm cách bố trí ở trên để layout-land thư mục trong res (nếu bạn không có một tạo ra một thư mục có tên layout-land trong res) bây giờ trong mặc định layout thư mục thêm xml này

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:gravity="center" > 
<ru.mw.widget.DrawableImageView 
    android:id="@+id/imageView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true" 
    android:adjustViewBounds="true" 
    /> 

<Button 
    android:id="@+id/processButton" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/imageView" 
    android:layout_centerHorizontal="true" 
    android:text="@string/str" /> 

<TextView 
    android:id="@+id/textView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/imageView" 
    android:layout_centerHorizontal="true" 
    android:text="@string/str" 
    android:textColor="?android:attr/textColorTertiary" /> 

</RelativeLayout> 

Thats it.

+0

Ví dụ hay, +1, nhưng tôi chỉnh sửa câu hỏi của mình một chút ... – ADK

+0

chỉnh sửa câu trả lời, vui lòng xem –

+0

Tôi hy vọng điều này có thể đạt được với một bố cục, nhưng bạn nói đúng, cảm ơn! – ADK

1

Cố gắng thêm android:layout_alignParentBottom="true" nút:

<Button 
    android:id="@+id/processButton" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/str" 
    android:layout_below="@+id/imageView" 
    android:layout_centerHorizontal="true" 
    android:layout_alignParentBottom="true" 
    /> 
1
  1. Căn chỉnh nút về phía dưới cùng bằng cách sử dụng layout_alignParentBottom="true".
  2. ImageView giữa TextViewButton

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

<TextView 
     android:id="@+id/textView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/str" 
     android:textAppearance="@android:style/TextAppearance.Small" 
     android:textColor="?android:attr/textColorTertiary" 
     android:layout_centerHorizontal="true" 
     /> 

<Button 
     android:id="@+id/processButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/str" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     /> 

<ru.mw.widget.DrawableImageView 
     android:id="@+id/imageView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/textView" 
     android:layout_above="@+id/processButton" 
     android:adjustViewBounds="true" 
     android:layout_centerHorizontal="true" 
     android:scaleType="centerCrop" 
     /> 

</RelativeLayout> 
Các vấn đề liên quan