2012-05-22 41 views
6

Tôi đang thực hiện dự án Android. Tại sao id ImageView iv1 và iv2 không ở chế độ toàn màn hình? Tôi đã đặt XML tôi xuống ở đây:Tại sao ImageView không ở chế độ toàn màn hình?

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:id="@+id/layout1" 
       android:orientation="vertical" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:paddingBottom="10px" 
       android:paddingLeft="10px" 
> 
    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
    > 
     <ImageView 
      android:id="@+id/iv1" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:visibility="invisible" 
     /> 

     <ImageView 
      android:id="@+id/iv2" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:visibility="invisible" 
     /> 

      <ImageButton 
      android:id="@+id/menu_btn" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:layout_toRightOf="@+id/BunyiIng" 
      android:src="@drawable/menu_btn" 
      android:background="@null" 
     /> 

     <ImageView 
      android:id="@+id/image_logo" 
      android:src="@drawable/logo_vehicle" 
       android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="@null" 
      android:layout_marginTop="5px" 
     /> 

    </RelativeLayout> 
</LinearLayout> 

Nếu tôi đặt ImageViews trong LinearLayout, nó chặn RelativeLayout.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:id="@+id/layout1" 
       android:orientation="vertical" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:paddingBottom="10px" 
       android:paddingLeft="10px" 
> 
    <ImageView 
      android:id="@+id/iv1" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:visibility="invisible" 
    /> 

    <ImageView 
     android:id="@+id/iv2" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:visibility="invisible" 
    /> 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
    > 

Nhưng nếu Imageview được đặt bên dưới RelativeLayout, nhưng bên trong LinearLayout, ImageView sẽ không hiển thị hình ảnh.

</RelativeLayout> 

    <ImageView 
      android:id="@+id/iv1" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:visibility="invisible" 
    /> 

    <ImageView 
      android:id="@+id/iv2" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:visibility="invisible" 
    /> 
</LinearLayout> 

Làm cách nào để giải quyết? Tôi muốn ImageView hiển thị hình ảnh ở chế độ toàn màn hình.

+0

Hãy thử điều này một lần - 'android: scaleType = fitXY' – Praveenkumar

Trả lời

24
  1. Bạn có đệm cho việc bố trí tuyến tính.
  2. Bạn không có bất kỳ nội dung nào trong số lần xem hình ảnh để xem nội dung của nó, vì vậy bạn không thể xem nội dung của nó.
  3. Bạn đã đặt chế độ xem hình ảnh thành ẩn mặt, do đó bạn không thể xem nội dung của nó.
  4. Nếu bạn không quan tâm đến tỷ lệ cỡ ảnh, hãy sử dụng android: adjustViewBounds = "false" và android: scaleType = "fitXY".
+2

câu trả lời không có 4 tác phẩm của nó! bạn đã cứu sống của tôi. cảm ơn!! – user1008497

2

Sử dụng tài sản này để xem hình ảnh:

android:scaleType="fitXY" 
0

Tôi thấy rằng cả chiều cao và chiều rộng của ImageViews đều được đặt thành "fill_parent", vì vậy tôi đoán rằng bạn muốn cả hai đều co giãn trên toàn bộ màn hình. Trong trường hợp bạn muốn họ chỉ ngồi đó và sẽ không sử dụng chúng cho bất cứ điều gì sau này, hãy thêm

android:background="@drawable/your_drawable_here" 

cho cả bố cục tuyến tính và tương đối của bạn. Nó sẽ thêm một hình ảnh vào nền của bố cục, mở rộng nó để vừa với toàn bộ bố cục và lưu một số tài nguyên nếu tôi không nhầm.

Các vấn đề liên quan