2011-10-04 88 views
0

我有一個PizzaOverview。圖片太大而無法看到所有視圖

enter image description here

XML:

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    > 
    <TextView android:layout_height="wrap_content" android:layout_width="fill_parent" android:text="" android:id="@+id/pizza_tv" android:gravity="center_horizontal" android:textSize="15pt"></TextView> 
    <ImageView android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/pizza_iv" android:src="@drawable/icon" android:layout_gravity="center_horizontal"></ImageView> 
    <RatingBar android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/pizza_rb" android:layout_gravity="center_horizontal"></RatingBar> 
    <TextView android:layout_height="wrap_content" android:text="" android:id="@+id/pizza_date" android:gravity="center|center_horizontal" android:layout_width="fill_parent"></TextView> 

<RelativeLayout android:id="@+id/relativeLayout2" android:layout_width="fill_parent" android:layout_height="fill_parent"> 
     <Button android:text="close" android:layout_height="wrap_content" android:id="@+id/pizza_bt" android:layout_alignParentBottom="true" android:layout_width="fill_parent"></Button> 
    </RelativeLayout> 
    </LinearLayout> 

如果圖片太大的日期是不可見的。

enter image description here

回答

0

添加滾動視圖佈局或修復的imageview的

大小滾動視圖添加到您的佈局

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" 
> 
<ScrollView 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
> 
<LinearLayout 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" 
> 
<TextView android:layout_height="wrap_content" android:layout_width="fill_parent" android:text="" android:id="@+id/pizza_tv" android:gravity="center_horizontal" android:textSize="15pt"></TextView> 
<ImageView android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/pizza_iv" android:src="@drawable/icon" android:layout_gravity="center_horizontal"></ImageView> 
<RatingBar android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/pizza_rb" android:layout_gravity="center_horizontal"></RatingBar> 
<TextView android:layout_height="wrap_content" android:text="" android:id="@+id/pizza_date" android:gravity="center|center_horizontal" android:layout_width="fill_parent"></TextView> 

<RelativeLayout android:id="@+id/relativeLayout2" android:layout_width="fill_parent" android:layout_height="fill_parent"> 
    <Button android:text="close" android:layout_height="wrap_content" android:id="@+id/pizza_bt" android:layout_alignParentBottom="true" android:layout_width="fill_parent"></Button> 
</RelativeLayout> 
</LinearLayout> 
</ScrollView> 
</LinearLayout> 
0

確保您提供給活動圖像是正確的分辨率和尺寸。 另外請確保您有單獨的屏幕尺寸類別的佈局。

閱讀Android文檔的this節上的佈局和管理不同屏幕尺寸的更多細節。它告訴你你需要的基礎知識。

0

您可以將您的圖像與評級酒吧,並在RelativeLayout它下面的文本。將marginBottom與您的RelativeLayout相加,等於您的Button的高度。然後放置您的文本,給它一個ID並添加android:layout_alignParentBottom="true"。將圖像的height設置爲fill_parent,並添加屬性android:layout:below="id_of_text"

0

您可以爲對方的回答狀態使屏幕滾動。但是如果你的內容是動態的(並且取決於設備有爭議說你的內容將總是動態的),你應該確保ImageView的界限設置正確。

在源代碼中你有:

<ImageView android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/pizza_iv" android:src="@drawable/icon" android:layout_gravity="center_horizontal"></ImageView> 

而應該有:

<ImageView android:layout_height="0dp" 
    android:weight="1" 
    android:layout_width="match_parent" 
    android:id="@+id/pizza_iv" 
    android:src="@drawable/icon" 
    android:layout_gravity="center_horizontal" 
    android:scaleType="centerInside"/> 

weight額外的屬性將讓你的看法填寫沿邊界設置方向的任何可用空間LinearLayout中。這取決於沿着該方向的其他視圖的權重(因爲其他視圖在這種情況下沒有權重值,它將填充所有空間直到固定視圖的邊緣)。

scaleType="centerInside"的額外屬性將使您的圖像位於您建議的邊界的中心(即垂直的屏幕寬度和所有可用空間),而不會增大到足以重疊邊界容器。

使用ImageView時,請記住ImageView是圖像的邊界容器。它可以儘可能大或者儘可能小,但僅僅是告訴UI在何處放置圖像的機制。 scaleType屬性用於說明如何將圖像放置在此邊界計數器中。在ImageView上使用"wrap_content"是無效的,並且可能會在設計的後期導致麻煩(特別是在考慮不同設備時)。