如何选择合适的图片尺寸

时间:2011-02-15 14:49:18

标签: android

HY!

我在视图上有两张照片,而在按钮上有一个按钮。

但问题是最后一张照片是在按钮上绘制的,而不是在第一张照片下面。所以按钮上的按钮是不可见的。

Screenshot

XML:

<?xml version="1.0" encoding="utf-8"?>
    <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> <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>

2 个答案:

答案 0 :(得分:0)

你在错误的地方打开RelativeLayout,所以里面唯一的东西就是Button 你应该把它放在前面并使用一些android:layout_below属性为所有元素选择正确的位置

有很多方法可以创建布局,如果你想使用RelativeLayout,你必须以正确的方式使用它。正确的方法是在其中放入2个或更多视图,并使用属性android:layout_below或类似属性告诉,其中是一个对象相对于另一个对象的位置。

例如,您希望第一个图像 over 第二个?您已将它们放在相同的相对布局中,并在第二个图像中放入属性android:layout_below="@id/1st_image_id"

答案 1 :(得分:0)

试试这个

<?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>