Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了带有scrollview的android自定义对话框将按钮从屏幕上移开大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个自定义对话框,其布局如下:
<RelativeLayout
    xmlns:android="http://scheR_187_11845@as.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/mylayout">
   <LinearLayout
       android:id="@+id/title"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:orientation="vertical">
       <TextView ... />
       <TextView .../>
    </LinearLayout>
    <ScrollView
       android:id="@+id/scrollView"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:layouT_Below="@+id/title">
       <LinearLayout ...>
           <TextView ...
              android:text="lots of text........" />
           <TextView .../>
       </LinearLayout>
     </ScrollView
  <RelativeLayout ...
     android:layouT_Below="@+id/scrollView">
     <Button ...>
     <Button ...>
  </RelativeLayout>
</RelativeLayout>

我的问题是滚动视图是当滚动视图中的文本太多时,下面的按钮会从对话框中向下推.我已经能够通过使用android:layout_alignParentBottom =“true”将包含按钮的RelativeLayout锚定到底部来阻止它,但是当滚动视图中的文本较少时,我将整个对话框拉伸到屏幕底部我不希望这样.

我怎样才能得到这样的布局:

[SOME TEXT]
[Scrollable region]
[Buttons]

解决方法

尝试使用LinearLayout而不是RelativeLayout将按钮放在单独的布局中,并在按钮布局上加权.
LinearLayout - top level start,android:layout_weight="0"
LinearLayout with TextViews embeded,android:layout_weight="1"
LinearLayout with ScrollView embeded,android:layout_weight="1"
LinearLayout with Buttons embeded,android:layout_weight="1"
LinearLayout - top level finish,android:layout_weight="0"

大佬总结

以上是大佬教程为你收集整理的带有scrollview的android自定义对话框将按钮从屏幕上移开全部内容,希望文章能够帮你解决带有scrollview的android自定义对话框将按钮从屏幕上移开所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。