2013-05-05 33 views
14

Đây file layout của tôi:Android IMAGExem choán hết chiều rộng màn hình

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:orientation="vertical" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
android:background="#000" 
tools:context=".CproductDetails" > 

    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/shape_bg" 
     > 

     <ImageView 
      android:id="@+id/product_image" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:src="@drawable/ic_tweet_placeholder_photo_dark_error" 
      android:scaleType="center" /> 

     <TextView 
      android:id="@+id/product_name" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textIsSelectable="true" 
      android:textColor="#95ab56" 
      android:textSize="20sp" 
      android:layout_marginTop="7dip" /> 

     <TextView 
      android:id="@+id/product_price" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textIsSelectable="true" 
      android:textSize="20sp" 
      android:textColor="#efeeea" /> 

     <TextView 
      android:id="@+id/product_commerce" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textIsSelectable="true" 
      android:textSize="20sp" /> 

     <TextView 
      android:id="@+id/product_city" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textIsSelectable="true" 
      android:textSize="15sp" 
      android:layout_marginTop="10dip" 
      android:layout_marginBottom="10dip" /> 

     <TextView 
      android:id="@+id/product_township" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textIsSelectable="true" 
      android:textSize="15sp" 
      android:visibility="gone" 
      android:layout_marginBottom="10dip" 
      android:drawableLeft="@drawable/location_place" 
      android:drawablePadding="7dip" /> 

     <TextView 
      android:id="@+id/product_website" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textIsSelectable="true" 
      android:autoLink="web" 
      android:textSize="15sp" 
      android:drawableLeft="@drawable/location_web_site" 
      android:drawablePadding="7dip" 
      android:visibility="gone" /> 

     <TextView 
      android:id="@+id/product_tel" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textIsSelectable="true" 
      android:textSize="20sp" 
      android:drawableLeft="@drawable/device_access_call" 
      android:drawablePadding="7dip" 
      android:visibility="gone" /> 

    </LinearLayout> 

Kết quả trong một chiếc điện thoại:

enter image description here

và kết quả trong một tablet 7in:

enter image description here

Tôi muốn làm cho hình ảnh lấp đầy chiều rộng màn hình cũng trong máy tính bảng. Như Twitter ứng dụng ví dụ:

enter image description here

enter image description here

+0

Câu trả lời của bạn sẽ phụ thuộc vào bố cục của bạn, vậy tại sao bạn không đăng toàn bộ tệp bố cục XML? – MarsAtomic

+0

android: layout_height = "fill_parent" – Raghunandan

+0

@MarsAtomic done – tsil

Trả lời

8

Cảm ơn tất cả nhưng không có câu trả lời nào giải quyết được sự cố của tôi. Cuối cùng tôi đã sử dụng lớp ScaleImageView của Maurycy Wojtowicz.

này xem sẽ tự động xác định chiều rộng hoặc chiều cao bằng cách xác định nếu chiều cao hoặc chiều rộng được thiết lập và mở rộng kích thước khác tùy thuộc vào những hình ảnh kích thước

+0

trang web bị lỗi, vui lòng cập nhật – fersarr

+0

@fersarr hoàn tất! – tsil

+0

Lớp này thêm thủ công centerInside hoặc centerCrop vào hình ảnh. Nó là một phiên bản cồng kềnh của nhiều câu trả lời tốt hơn về cả hai điều này và 10 bản sao của câu hỏi này mà không yêu cầu một lớp không liên quan. – LoungeKatt

5

sử dụng android:scaleType="fitXY".

Điều này sẽ chia tỷ lệ hình ảnh theo X và Y một cách độc lập, sao cho src khớp chính xác. Điều này có thể thay đổi tỷ lệ khung hình của src.

+2

tương đối vô dụng đối với hầu hết các ảnh, vì tỷ lệ co là quan trọng – lilbyrdie

40

Nghe có vẻ như bạn muốn sử dụng android:scaleType="fitCenter"android:adjustViewBounds="true" trên ImageView của bạn.

-2

android: scaleType = "fitXY" .Go cho it

+0

fitXY sẽ lấy trục x và y hoàn chỉnh như chiều cao bố cục được mô tả của chúng tôi –

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