开发者

How to choose the right picture size

Hy!

I have two pictures on the view and a button at the buttom.

But the Problem is that the last picture is drawn at the button and not under the first on. So the button at the buttom is unvisible.

How to choose the right picture size

XML:

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android开发者_StackOverflow:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="vertical">
    <TextView android:layout_height="wrap_content" android:id="@+id/mainscreen" android:layout_width="fill_parent" android:text="Selected Channel" android:gravity="center"></TextView>
    <ImageView android:id="@+id/ImageView01" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
    <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/mainscreen_state"></TextView>
    <ImageView android:layout_width="wrap_content" android:layout_centerHorizontal="true" android:layout_height="wrap_content" android:id="@+id/ImageAd" android:layout_gravity="center"></ImageView> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_height="fill_parent"
        android:layout_width="fill_parent">


    <Button android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:id="@+id/mainscreen_btchange" 
        android:text="Change State"></Button>


    </RelativeLayout>
    </LinearLayout>


Try this one

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

  <RelativeLayout
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:layout_alignParentTop="true">

    <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_height="wrap_content"
      android:layout_width="fill_parent"
      android:orientation="vertical">
      <TextView
        android:layout_height="wrap_content"
        android:id="@+id/mainscreen"
        android:layout_width="fill_parent"
        android:text="Selected Channel"
        android:gravity="center"></TextView>
      <ImageView
        android:id="@+id/ImageView01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"></ImageView>
      <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/mainscreen_state"></TextView>
      <ImageView
        android:layout_width="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_height="wrap_content"
        android:id="@+id/ImageAd"
        android:layout_gravity="center"></ImageView>
    </LinearLayout>
  </RelativeLayout>
  <RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:layout_alignParentBottom="true"
    >
    <Button
      android:layout_width="wrap_content"
      android:text="Change State"
      android:layout_height="wrap_content"
      android:id="@+id/mainscreen_btchange"
      android:layout_centerHorizontal="true"></Button>

  </RelativeLayout>
</RelativeLayout>


you open the RelativeLayout in the wrong place, so that the only thing inside is the Button you should put it before and use some android:layout_below attributes to choose the right position for all the elements

there are many ways to create a layout, if you want to use a RelativeLayout you have to use it the right way. the right way is to put inside it 2 or more Views and tell by using the attribute android:layout_below or similar attributes where is the position of one object in a relative way to the other.

for example you want the first image over the second? you have put them in the same relative layout and put in the second image an attribute android:layout_below="@id/1st_image_id"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜