Как изображение должно быть в области между двумя кнопками?

1

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>

как это сделать, я с нетерпением жду ответов... спасибо за все ответы заранее....

Теги:

3 ответа

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 прежде всего спасибо за быстрый ответ ... когда я запускаю этот код, кнопки расположены слева и справа, но он находится сверху макета, а изображение находится ниже кнопки, на самом деле я хочу, чтобы кнопки были слева и справа от изображения и также между изображениями я думаю, что теперь я могу объяснить мою проблему ...
  • 0
    замените android:layout_alignParentTop="true" на android:layout_centerVertical="true" в обоих объявлениях Button , и они будут отображаться в нужном месте.
Показать ещё 2 комментария
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
    хорошо, приты круто .. хитрость
  • 0
    Спасибо .... так что у тебя есть выход ... круто
0

Попробуйте горизонтальную ориентацию для макета, которая должна быть достаточно хорошей. android: orientation = "vertical" > Вместо этого используйте горизонтальный. Также измените последовательность в макете на кнопку, изображение, кнопку.

Ещё вопросы

Сообщество Overcoder
Наверх
Меню