日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java 固定listview_listview Button始终放在底部示例

發布時間:2023/12/15 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java 固定listview_listview Button始终放在底部示例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

android實現底部布局往往使用RelativeLayout的布局方式,并且設置android:layout_alignParentBottom=”true”,這樣很容易實現底部布局。然而對于比較復雜的布局簡單的屬性設置無法達到這樣的效果,例如top,center,bottom三層的布局,很可能因為中間層(center)的數據太多而將無法顯示全或者將bottom層擠下去。解決這個問題,在采用RelativeLayout布局時,除了設置android:layout_alignParentBottom=”true”外,還需要對中間層進行屬性進行設置:android:layout_above=”@id/bottom”

android:layout_below=”@id/top”。這樣的設置即確保center層能處于中間位置,也可以通過自適應顯示滾動條。

以下的例子就是實現三層布局的底部布局的功能。如圖1,2。

?

圖-1 三層的底部布局界面

?

圖 2 彈出輸入法時顯示的底部按鈕

項目只是實現主要的數據填充及布局,故只是簡單的文件加載。以下是源碼:

BottomTestActivity.java

package com.BottomTest.main;

import java.util.ArrayList;

import java.util.HashMap;

import android.app.Activity;

import android.os.Bundle;

import android.widget.ListView;

import android.widget.SimpleAdapter;

publicclass BottomTestActivityextends Activity {

/** Called when the activity is first created. */

@Override

publicvoid onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

ListView list = (ListView) findViewById(R.id.friends);

//存儲數據的數組列表

ArrayList> listData=new ArrayList>();

String []name={"William","Charles","Linng","Json","Bob","Carli"};

String []id={"12","16","33","21","34","22"};

for(int i=0;i<6;i++){

HashMap map=new HashMap();

map.put("friend_image", R.drawable.icon);

map.put("friend_username", name[i]);

map.put("friend_id", id[i]);

listData.add(map);

}

//適配器

SimpleAdapter listItemAdapter=new SimpleAdapter(this,

listData,

R.layout.item,

new String[] {"friend_image","friend_username","friend_id" },

newint[] { R.id.friend_image, R.id.friend_username, R.id.friend_id });

list.setAdapter(listItemAdapter);

}

}

主要布局文件

main.xml

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:orientation="vertical">

android:layout_width="fill_parent"

android:layout_height="wrap_content" >

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:orientation="horizontal" >

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_marginTop="6dip"

android:layout_marginLeft="12dip"

android:singleLine="true"

android:numeric="integer"

android:imeOptions="actionDone"

android:hint="輸入用戶ID"

android:layout_weight="1"/>

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_marginTop="4dip"

android:layout_weight="3"

android:text="查看"/>

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:orientation="vertical"

android:layout_above="@id/bottom"

android:layout_below="@id/top">

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="好友列表"

android:paddingTop="6dip"

android:paddingLeft="2dip"

android:layout_marginLeft="10dip"/>

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_marginBottom="6dip"/>

android:background="@drawable/bg"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:orientation="horizontal"

android:layout_alignParentBottom="true" >

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_marginTop="2dip"

android:text="刷新用戶列表"

android:layout_weight="1"/>

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_marginTop="2dip"

android:text="返回"

android:layout_weight="1"/>

listview item內容的布局文件

item.xml

android:id="@+id/RelativeLayout"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:paddingBottom="4dip"

android:paddingRight="12dip">

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:paddingTop="6dip"

android:paddingLeft="2dip"

android:layout_centerVertical="true"

android:layout_alignParentLeft="true"/>

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:textSize="18dip"

android:textColor="#ccc"

android:paddingTop="6dip"

android:paddingRight="2dip"

android:layout_toRightOf="@id/friend_image" />

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_below="@+id/friend_username"

android:layout_marginRight="36dip"

android:paddingRight="2dip"

android:layout_toRightOf="@id/friend_image"

android:textColor="#fff"

android:maxLines="2"/>

總結

以上是生活随笔為你收集整理的java 固定listview_listview Button始终放在底部示例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。