2012-02-22 131 views
1

我使用文件main.xml來設計Android中的UI。我不知道爲什麼最後的TextView(id:ImageDescription)不起作用。如果我刪除ImageView標記,則最後的TextView將再次起作用。 這是我的截圖。當沒有ImageView標籤,而第二時有ImageViewAndroid佈局無法正常工作

not <code>ImageView</code> tag with <code>ImageView</code> tag

正如你看到的,在第一時有圖像,我看不到線Image descriptor: a cartoon tiger。 這裏是我的main.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 

    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <TextView 
     android:id="@+id/imageTitle" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/test_image_title"/> 

    <TextView 
     android:id="@+id/imageDate" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/test_image_date"/> 


    <ImageView 
     android:id="@+id/imageDisplay" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:contentDescription="@string/test_contentDescription" 
     android:src="@drawable/test_image"/> 

    <ScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
     <TextView 
      android:id="@+id/imageDescription" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/test_image_description"/> 
    </ScrollView>   

</LinearLayout> 

感謝幫助我:)

+0

來自ScrollView文檔'TextView類也照顧它自己的滾動,所以不需要ScrollView' – Selvin 2012-02-22 15:30:29

+2

@Selvin是的。我認爲問題不是'ScrollView',因爲當我刪除'ScrollView'標記時,仍然沒有發生任何不同:( – hqt 2012-02-22 15:44:35

+2

它非常簡單明顯......圖像太大......它似乎在頂部有黑條,底部...也許你應該把圖像和desription到另一個linearlayout,然後把這個linearlayout滾動查看... – Selvin 2012-02-22 15:48:35

回答

1

你加入以下imageview的並且過於你的滾動視圖有有和HIGHT作爲FILL_PARENT,一旦嘗試這個

您imageDescription的TextView
<TextView 
     android:id="@+id/imageDate" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/test_image_date"/> 


    <ScrollView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 
     <TextView 
      android:id="@+id/imageDescription" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/test_image_description"/> 
    </ScrollView> 

    <ImageView 
     android:id="@+id/imageDisplay" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:contentDescription="@string/test_contentDescription" 
     android:src="@drawable/test_image"/> 

我認爲圖像太大,如果是這種情況,請嘗試通過以適當的百分比爲圖像和文本視圖指定layout:weight參數。

+1

是的,你的代碼工作,但不是我想要的用戶界面,我想在下面的圖像描述。 ? – hqt 2012-02-22 15:28:49

+0

然後,只改變你的滾動視圖的寬度和高度,就像在我的帖子中一樣,爲什麼因爲它試圖佔用父母的總體大小 – sankar 2012-02-22 15:48:36

+1

我認爲圖像太大,如果是這種情況,請嘗試指定佈局:圖像和文本視圖在適當的比例。 – sankar 2012-02-22 15:57:58

1

試圖將XML部分

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

改變

<ScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 

因爲你ScrollView試圖那樣大,高度的LinearLayout

+0

沒有什麼變化:( – hqt 2012-02-22 15:43:10

+1

也沒有任何保證金或填充XML在你的ImageView中,但它的方式在你的TextView下。你的testimage上面和下面都沒有黑色或透明條紋,將ScrollView推出可視區域? – IBoS 2012-02-22 15:55:18

+2

是的,也許我的圖像有透明的三角形,但是當我把它作爲牆紙時,我看不到透明的三角形如何測試它,你知道嗎請教我:) – hqt 2012-02-22 16:29:07

1

我有我的問題的另一個答案,我發佈在這裏誰看過我的帖子,需要更多的答案。我使用android:adjustViewBounds="true"財產:)

相關問題