android底部按钮布局,在android中的相对布局底部需要一个按钮

我是Android新手.我正在创建一个带有可点击文本的应用程序.

所有可单击的文本都存在于一个数组中,然后该数组与ListView关联并显示在RelativeLayout中.

代码是 –

this.setListAdapter(new ArrayAdapter(this, R.layout.main, R.id.label, contact_name));

ListView lv = getListView();

main是相对布局,label是布局中的文本框id,contact_name是作为可点击文本的数组.这一切都很好.

最后,当数组非常大时,线性布局变得可滚动.

现在我想将此列表占用的区域限制为总屏幕高度的80%或90%,并在底部保留一个按钮,该按钮将打开一个新的页面/视图.在相对布局中包含按钮是为列表中的每个项添加一个按钮.更改相对布局的高度是更改列表中每个项目的高度.这得出结论,数组中的每个项目都与整个相对布局相关联,并且相对布局的数组用于显示所有项目.现在如何通过将相对布局列表从顶部限制到屏幕的80%来在底部放置一个按钮.

这是当前XML文件的样子

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical" >

android:id="@+id/btn"

android:layout_alignParentBottom="true"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_gravity="center_vertical"

android:text="Next"

/>

android:id="@+id/scroll"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_above="@id/btn">

android:id="@+id/label"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:padding="10dip"

android:textSize="16sp"

android:textStyle="bold" >

代码结束

输出是一个Next按钮数组,隐藏了实际内容.

这是我的Java代码

// Make the contact number parameter accessible to member functions of List View

final String[] f_contact_number = contact_number;

// Binding Array to ListAdapter

this.setListAdapter(new ArrayAdapter(this, R.layout.main, R.id.label, contact_name));

ListView lv = getListView();

// listening to single list item on click

lv.setOnItemClickListener(new OnItemClickListener() {

public void onItemClick(AdapterView> parent, View view,

int position, long id) {

Intent intent = new Intent(Intent.ACTION_CALL);

intent.setData(Uri.parse(f_contact_number[position]));

startActivity(intent);

}

});

Contact_number和contact_names是两个字符串数组,在单击contact_name时调用一个数字

Thanks

解决方法:

我想你应该这样做:

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical" >

android:id="@+id/btn"

android:layout_alignParentBottom="true"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_gravity="center_vertical"

android:text="Next"

/>

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_above="@id/btn">

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="Scroll view content"

>

因此按钮将粘贴到父级的底部,剩余的空间将被ScrollView占用

希望这可以帮助.

标签:android,android-linearlayout,android-button

来源: https://codeday.me/bug/20190831/1778071.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值