列表占用太多空间,无法查看带按钮的 EditText
我想要一个 ListView
,后跟一个 EdiText
,然后是 2 个按钮,例如:
ListView <NEWLINE>
EditText <NEWLINE>
Button1 Button2 <NEWLINE>
我有代码,如果列表很小,一切都会顺利。但是,如果列表有很多元素,它将占用所有空间,并且我将无法看到 EditText
或按钮。
我已将其精简到问题开始的部分:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="@+id/in"
android:layout_below="@id/button_contacts"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll"
android:layout_weight="1.0"
/>
<EditText
android:id="@+id/entry"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:drawable/editbox_background"
android:layout_below="@id/in" />
<Button
android:id="@+id/Convert"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@id/entry"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dip"
android:text="Convert" />
<Button
android:id="@+id/sendSMS"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_toLeftOf="@id/Convert"
android:layout_alignTop="@id/Convert"
android:text="Send" />
</RelativeLayout>
我该如何解决这个问题?
I want to have a ListView
, followed by a EdiText
, folowed by 2 buttons like:
ListView <NEWLINE>
EditText <NEWLINE>
Button1 Button2 <NEWLINE>
I have the code and if the list is small everything goes well. However, if the list has many elements it will take all the space and I won't be able to see the EditText
or the buttons.
I have trimmed it down to the part where the problem starts:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="@+id/in"
android:layout_below="@id/button_contacts"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll"
android:layout_weight="1.0"
/>
<EditText
android:id="@+id/entry"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:drawable/editbox_background"
android:layout_below="@id/in" />
<Button
android:id="@+id/Convert"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@id/entry"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dip"
android:text="Convert" />
<Button
android:id="@+id/sendSMS"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_toLeftOf="@id/Convert"
android:layout_alignTop="@id/Convert"
android:text="Send" />
</RelativeLayout>
How can I solve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
下面的代码对我有用,我希望它也对你有用......
the below code works for me and i hope it will work for you too...
因为在 ListView 中你使用 android:layout_weight="1.0" 所以,它占用了所有空间。您应该添加 1 个布局来包装您的 Text、Buttom 等,并添加此 android:layout_weight="2.0" 或 3.0(由您决定)尝试。
PS如果仍然不起作用尝试将所有 android:layout_height="fill_parent" 更改为 android:layout_height="wrap_content"
Because in ListView you use android:layout_weight="1.0" so, it took all space. you should add 1 layout to wrap your Text,Buttom etc. and add this android:layout_weight="2.0" or 3.0 (it's up to you) Try.
P.S. If it still not work For Try change all android:layout_height="fill_parent" To android:layout_height="wrap_content"
您需要给列表视图一个固定的高度。
另一种选择是在代码中以编程方式设置高度。如果您这样做,您需要在 Activity 的 onWindowFocused() 方法中执行。然后,您可以通过编程方式将其设置为屏幕的一半。
You need to give your listview a fixed height.
Another choice is to set the height programmatically in the code. If you do this you need to do in the Activity's onWindowFocused() method. You can then programmatically set it to say half your screen.