2011-05-21 54 views
1

HIII ...我能夠從圖像的URL,實際上圖像的URL被存儲在一個字符串數組顯示圖像和我使用了顯示圖像圖像應該如何處於兩個按鈕之間的區域?

URL aURL = new URL(imagePath); 
URLConnection conn = aURL.openConnection(); 
conn.connect(); 
InputStream is = conn.getInputStream(); 
BufferedInputStream bis = new BufferedInputStream(is); 
Bitmap bm = BitmapFactory.decodeStream(bis); 
bis.close(); 
is.close(); 

imageLoader.setImageBitmap(bm); 

imageLoader.setImageBitmap(bm); 

現在我想添加兩個按鈕,這將留下和形象權是指圖像會出現兩個按鍵之間的....我的main.xml是

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    android:orientation="vertical"> 
    <ImageView android:id="@+id/imageLoader" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 
    <Button android:text="Button" android:id="@+id/next" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 
    </Button> 
    <Button android:text="Button" android:id="@+id/back" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 
    </Button> 
</LinearLayout> 

如何做到這一點我熱切提前等待responces ...感謝所有responces ... 。

回答

0

您應該使用RelativeLayout實現這一點,是這樣的:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="fill_parent"> 
    <Button android:id="@+id/back" android:text="Back" 
     android:layout_width="wrap_content" android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" /> 
    <Button android:id="@+id/next" android:text="Next" 
     android:layout_width="wrap_content" android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" /> 
    <ImageView android:id="@+id/imageLoader" 
     android:layout_width="wrap_content" android:layout_height="fill_parent" 
     android:layout_toLeftOf="@id/next" 
     android:layout_toRightOf="@id/back" /> 
</RelativeLayout> 

Buttons在視圖中垂直居中,因此他們將鹼液左側和包裝圖像的右側,你應該改變android:layout_alignParentTop="true"在他們的聲明android:layout_centerVertical="true"

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="fill_parent"> 
    <Button android:id="@+id/back" android:text="Back" 
     android:layout_width="wrap_content" android:layout_height="wrap_content" 
     android:layout_centerVertical="true" /> 
    <Button android:id="@+id/next" android:text="Next" 
     android:layout_width="wrap_content" android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_centerVertical="true" /> 
    <ImageView android:id="@+id/imageLoader" 
     android:layout_width="wrap_content" android:layout_height="fill_parent" 
     android:layout_toLeftOf="@id/next" 
     android:layout_toRightOf="@id/back" /> 
</RelativeLayout> 
+0

@rekazeru首先感謝這麼快的響應...當我運行這個代碼按鈕是左和右,但它是在佈局和圖像的頂部是從按鈕下面實際上我想按鈕應該是在圖像的左側和右側,也是圖像之間我認爲我現在可以解釋我的問題... – 2011-05-21 09:23:41

+0

更改'android:layout_alignParentTop =「tru在'Button'聲明中將e:''轉換爲'android:layout_centerVertical =「true」',並且它們將顯示在所需的位置。 – rekaszeru 2011-05-21 09:32:53

+0

非常感謝它的工作....你非常有幫助... :) – 2011-05-21 09:52:22

0

嘗試的佈局應足夠好臥式方向。 android:orientation =「vertical」>改爲使用橫向。還要將佈局中的序列更改爲按鈕,圖像,按鈕。

0

嘗試......

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" android:layout_height="fill_parent" 
android:orientation="vertical"> 
<ImageView android:id="@+id/imageLoader" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 
<Button android:text="Button" android:id="@+id/next" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:android:layout_toLeftOf="@+id/imageLoader" 
    android:layout_marginTop="30dip"> 
</Button> 
<Button android:text="Button" android:id="@+id/back" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_toRightOf="@+id/imageLoader" 
    android:layout_marginTop="30dip"> 
</Button> 

調整前值按烏爾要求...希望它有助於ü...

+0

好吧preety cool..trick – 2011-05-21 11:30:53

+0

謝謝你....所以你得到了輸出...酷 – Taruni 2011-05-21 11:50:07