如何添加背景图片固定头部,然后在Android上滚动列表视图 [英] How to add background image with fixed header then a scrolling listview in android

查看:216
本文介绍了如何添加背景图片固定头部,然后在Android上滚动列表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我初学android的。我只是想清除我的概念。所以我开始做我的机器人。我第一个屏幕要在背景图像。然后添加一个固定头(包头上有三个按钮)。然后滚动列表视图?可以请你帮我。我知道我必须做的XML编码。刚给我一些暗示,这样我就可以开始.. 。我拥有的所有图像。

 <的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:工具=htt​​p://schemas.android.com/tool​​s
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:paddingBottom会=@扪/ activity_vertical_margin
    机器人:paddingLeft =@扪/ activity_horizo​​ntal_margin
    机器人:paddingRight =@扪/ activity_horizo​​ntal_margin
    机器人:paddingTop =@扪/ activity_vertical_margin
    工具:上下文=。First_activity
    机器人:背景=@绘制/一个>
   < RelativeLayout的
    机器人:ID =@ + ID / main_title
    机器人:layout_width =match_parent
    机器人:layout_height =WRAP_CONTENT
      机器人:SRC =@绘制/头>    < RelativeLayout的
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentRight =真
        >        <的ImageButton
              机器人:ID =@ + ID /设置            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
             机器人:SRC =@绘制/设置/>        <的ImageButton
            机器人:ID =@ + ID /加
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:SRC =@绘制/添加/>        <的ImageButton
             机器人:ID =@ + ID /编辑
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
             机器人:SRC =@绘制/编辑/>    < / RelativeLayout的>< / RelativeLayout的>   < ListView控件
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent>
< /&的ListView GT;
< / RelativeLayout的>

到现在我这个高达成功。

头图像不显示..three按钮不会显示..?


解决方案

 <的ImageButton
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT/>
    >


  1. 在您的code我不明白为什么你有这样的额外'>'在第三年底的ImageButton


  2. 把你的ListView父里面 RelativeLayout的是明智的。


  3. 此外,由于在@ codeR提到的,改变你的形象的名字,图像和布局的xml文件只接受[A-Z,0-9,_]在他们的名字。

修改 -

您已经使用匹配父'的的ListView ,其母公司是你的主要相对布局,因此它占据所有空间,你的头没有显示,你会必须使用的android:背景,不SRC。它将工作即可。
你写了你的三个imagebuttons什么,是线性laout。对于RelativeLayout的,事情会略有不同。检查了这一点,你的三张图像将显示这种方式 -

使用下面的布局 -
`

 < RelativeLayout的
    机器人:ID =@ + ID / main_title
    机器人:layout_width =match_parent
    机器人:layout_height =WRAP_CONTENT
    机器人:背景=@绘制/头>    <的ImageButton
        机器人:ID =@ + ID / imageView1
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentRight =真
        机器人:layout_alignParentTop =真
        机器人:SRC =@绘制/ ic_launcher/>    <的ImageButton
        机器人:ID =@ + ID / imageView2
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentTop =真
        机器人:layout_toLeftOf =@ + ID / imageView1
        机器人:SRC =@绘制/ ic_launcher/>    <的ImageButton
        机器人:ID =@ + ID / imageView3
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentTop =真
        机器人:layout_toLeftOf =@ + ID / imageView2
        机器人:SRC =@绘制/ ic_launcher/>< / RelativeLayout的>< ListView控件
    机器人:ID =@ + ID / ListView1的
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:layout_alignParentBottom =真
    机器人:layout_alignParentLeft =真
    机器人:layout_alignParentRight =真
    机器人:layout_marginBottom =104dp
    机器人:layout_below =@ ID / main_title>
< /&的ListView GT;

`

I am beginner in android .I just want to clear my concepts .So i start making my first screen in android .I want to add on background image .Then one fixed header (on header there is three buttons ).Then scrolling list view ?can you please help me .I know i have to do coding in xml .just give me some hint so that i can start.. .I have all images .

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".First_activity" 
    android:background="@drawable/a">
   <RelativeLayout
    android:id="@+id/main_title"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
      android:src="@drawable/header" >

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

        <ImageButton
              android:id="@+id/setting"

            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
             android:src="@drawable/settings" />

        <ImageButton
            android:id="@+id/add"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            android:src="@drawable/add"/>

        <ImageButton
             android:id="@+id/edit"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
             android:src="@drawable/edit"  />

    </RelativeLayout>

</RelativeLayout>

   <ListView
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
</ListView>
</RelativeLayout>

Till now i succeed upto this..

header image is not display ..three button are not shown..?

解决方案

    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    >

  1. In your code I can't understand why you have this extra '>' at the end of third imageButton?

  2. Putting your listview inside the parent RelativeLayout is advisable.

  3. And, as @thecoder mentioned, change your images names, as images and layout xml files only accept [a-z,0-9,_] in their names.

EDIT--

you have used 'match parent' for ListView, and its parent is your main relative layout, so it occupies all the space, your header is not showing, you will have to use android:background, not src. It will work then. What you wrote for your three imagebuttons, is for linear laout. For relativelayout, things will be slightly different. Check this out, your three images will be shown this way -

use following layout - `

<RelativeLayout
    android:id="@+id/main_title"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/header" >

    <ImageButton
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:src="@drawable/ic_launcher" />

    <ImageButton
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toLeftOf="@+id/imageView1"
        android:src="@drawable/ic_launcher" />

    <ImageButton
        android:id="@+id/imageView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toLeftOf="@+id/imageView2"
        android:src="@drawable/ic_launcher" />

</RelativeLayout>

<ListView
    android:id="@+id/listView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_marginBottom="104dp" 
    android:layout_below="@id/main_title">
</ListView>

`

这篇关于如何添加背景图片固定头部,然后在Android上滚动列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆