【问题标题】:Shows image top of screen在屏幕顶部显示图像
【发布时间】:2013-09-25 16:08:04
【问题描述】:

我想在屏幕顶部和屏幕底部显示一些按钮的图像。我写了这段代码,但图像没有显示!我怎么解决这个问题?如果我将图像转换为相对布局之外,图像显示页面顶部,但视图显示就像我分离了首页的底部页面。为什么?

按钮的另一个问题。 btn4 按钮显示在另一个按钮之上?为什么?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:orientation="vertical"
          android:background="@drawable/background">

<RelativeLayout 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="0"
    android:layout_gravity="bottom">
     <ImageView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/smallyelowbar"
        android:adjustViewBounds="true"
        android:scaleType="fitXY"
        android:layout_alignParentTop="true"/>
        <FrameLayout
            android:id="@+id/frameLayout"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:background="@drawable/background" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_alignParentBottom="true">
        <Button android:id="@+id/btn1"
            android:layout_width="0dip"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:background="@drawable/more_selector"/>
        <Button 
            android:id="@+id/btn2"
            android:layout_width="0dip"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:background="@drawable/contact_selector"/>
        <Button android:id="@+id/btn3"
            android:layout_width="0dip"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:background="@drawable/product_selector"/>
        <Button android:id="@+id/btn4"
            android:layout_width="0dip"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:background="@drawable/introduce_selector"/>
        </LinearLayout>
</RelativeLayout>
</LinearLayout>

【问题讨论】:

  • 为什么你把你的布局包裹在线性布局中,你不能使用RelativeLayout本身
  • 感谢您的快速回复,但我无法理解您在说什么。请多解释。

标签: android button view


【解决方案1】:

在我看来,您的 FrameLayout 将 ImageView 隐藏在它后面。 尝试将 FrameLayout 置于 ImageView 下方(通过在其上设置 android:below= 属性,或将 ImageView 置于 xml 中的 FrameLayout 之上)。

【讨论】:

    【解决方案2】:

    你可以试试这个。

    <?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"
        android:background="#FFFFFF"
        android:orientation="vertical" >
    
        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_above="@+id/bottom" >
    
            <ImageView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:adjustViewBounds="true"
                android:background="#495663"
                android:scaleType="fitXY" />
        </RelativeLayout>
    
        <RelativeLayout
            android:id="@+id/bottom"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:orientation="horizontal" >
    
            <Button
                android:id="@+id/btn1"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#DBEAF9" />
    
            <Button
                android:id="@+id/btn2"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#DBEAF9" />
    
            <Button
                android:id="@+id/btn3"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#DBEAF9" />
    
            <Button
                android:id="@+id/btn4"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#DBEAF9" />
        </RelativeLayout>
    
    </RelativeLayout>
    

    完美工作。编码愉快!!

    【讨论】:

      【解决方案3】:

      试试这个 XML

      <?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"
          android:orientation="vertical" >
      
          <RelativeLayout
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_above="@+id/relative_btngroup"
              android:background="@drawable/ic_launcher" >
      
              <ImageView
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:layout_alignParentTop="true"
                  android:adjustViewBounds="true"
                  android:scaleType="fitXY" />
      
              <FrameLayout
                  android:id="@+id/frameLayout"
                  android:layout_width="fill_parent"
                  android:layout_height="match_parent" />
          </RelativeLayout>
      
          <RelativeLayout
              android:id="@+id/relative_btngroup"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_alignParentBottom="true" >
      
              <Button
                  android:id="@+id/btn1"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content" />
      
              <Button
                  android:id="@+id/btn2"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_toRightOf="@+id/btn1" />
      
              <Button
                  android:id="@+id/btn3"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_toRightOf="@+id/btn2" />
      
              <Button
                  android:id="@+id/btn4"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_toRightOf="@+id/btn3" />
          </RelativeLayout>
      
      </RelativeLayout>
      

      【讨论】:

        【解决方案4】:

        这里的问题是您的 frameLayout 与您的图像视图重叠...这就是为什么当您将其移出相对布局时它会起作用。

        试试下面的代码

        <?xml version="1.0" encoding="utf-8"?>
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:orientation="vertical"
              android:background="@drawable/background">
        
        <RelativeLayout 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="0"
        android:layout_gravity="bottom">
            <FrameLayout
                android:id="@+id/frameLayout"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:background="@drawable/background" />
         <ImageView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:src="@drawable/smallyelowbar"
            android:adjustViewBounds="true"
            android:scaleType="fitXY"
            android:layout_alignParentTop="true"/>
        
        
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_alignParentBottom="true">
            <Button android:id="@+id/btn1"
                android:layout_width="0dip"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:background="@drawable/more_selector"/>
            <Button 
                android:id="@+id/btn2"
                android:layout_width="0dip"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:background="@drawable/contact_selector"/>
            <Button android:id="@+id/btn3"
                android:layout_width="0dip"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:background="@drawable/product_selector"/>
            <Button android:id="@+id/btn4"
                android:layout_width="0dip"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:background="@drawable/introduce_selector"/>
            </LinearLayout>
        </RelativeLayout>
        </LinearLayout>
        

        【讨论】:

          猜你喜欢
          • 2021-12-17
          • 1970-01-01
          • 2015-10-23
          • 1970-01-01
          • 2019-02-11
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多