标签:android android-linearlayout android-button
我是Android新手.我正在创建一个带有可点击文本的应用程序.
所有可单击的文本都存在于一个数组中,然后该数组与ListView关联并显示在RelativeLayout中.
代码是 –
this.setListAdapter(new ArrayAdapter<String>(this, R.layout.main, R.id.label, contact_name));
ListView lv = getListView();
main是相对布局,label是布局中的文本框id,contact_name是作为可点击文本的数组.这一切都很好.
最后,当数组非常大时,线性布局变得可滚动.
现在我想将此列表占用的区域限制为总屏幕高度的80%或90%,并在底部保留一个按钮,该按钮将打开一个新的页面/视图.在相对布局中包含按钮是为列表中的每个项添加一个按钮.更改相对布局的高度是更改列表中每个项目的高度.这得出结论,数组中的每个项目都与整个相对布局相关联,并且相对布局的数组用于显示所有项目.现在如何通过将相对布局列表从顶部限制到屏幕的80%来在底部放置一个按钮.
这是当前XML文件的样子
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
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"
/>
<ScrollView
android:id="@+id/scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/btn">
<TextView
android:id="@+id/label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dip"
android:textSize="16sp"
android:textStyle="bold" >
</TextView>
</ScrollView>
</RelativeLayout>
代码结束
输出是一个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<String>(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
解决方法:
我想你应该这样做:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
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"
/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/btn">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Scroll view content"
>
</TextView>
</ScrollView>
</RelativeLayout>
因此按钮将粘贴到父级的底部,剩余的空间将被ScrollView占用
希望这可以帮助.
标签:android,android-linearlayout,android-button 来源: https://codeday.me/bug/20190831/1778071.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。