hiii... я могу показать изображение из 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);
теперь я хочу добавить две кнопки, которые будут слева и справа от изображения, означает, что изображение будет находиться между двумя кнопками.... my 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>
как это сделать, я с нетерпением жду ответов... спасибо за все ответы заранее....
Вы должны использовать 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>
Попробуйте это...
<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>
Отрегулируйте верхнее значение в соответствии с требованиями ур... Надеюсь, он поможет вам...
Попробуйте горизонтальную ориентацию для макета, которая должна быть достаточно хорошей. android: orientation = "vertical" > Вместо этого используйте горизонтальный. Также измените последовательность в макете на кнопку, изображение, кнопку.
android:layout_alignParentTop="true"
наandroid:layout_centerVertical="true"
в обоих объявленияхButton
, и они будут отображаться в нужном месте.