本文介绍了与滚动型机器人自定义对话框中按下按钮关闭屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的布局的自定义对话框:

 < RelativeLayout的
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:方向=垂直
    机器人:layout_width =match_parent
    机器人:layout_height =WRAP_CONTENT
    机器人:ID =@ + ID / mylayout>
   <的LinearLayout
       机器人:ID =@ + ID /标题
       机器人:layout_width =match_parent
       机器人:layout_height =WRAP_CONTENT
       机器人:方向=垂直>
       < TextView的... />
       < TextView的... />
    < / LinearLayout中>
    <滚动型
       机器人:ID =@ + ID /滚动视图
       机器人:layout_width =match_parent
       机器人:layout_height =WRAP_CONTENT
       机器人:layout_below =@ + ID /标题>
       < LinearLayout中...>
           < TextView中...
              机器人:文本=大量文字........的/>
           < TextView的... />
       < / LinearLayout中>
     < /滚动型
  < RelativeLayout的...
     机器人:layout_below =@ + ID /滚动视图>
     <按钮...>
     <按钮...>
  < / RelativeLayout的>
< / RelativeLayout的>
 

我的问题是,滚动视图的是,当在滚动视图过多文本,下面的按钮被下推出对话框。我已经能够prevent它锚定包含按钮,底部使用RelativeLayout的机器人:layout_alignParentBottom =真,但我一直延伸到屏幕底部的整个对话时,有更少的文字滚动视图,我不希望出现这种情况。

我怎样才能获得的布局是这样的:

  [一些文本]
[滚动区域]
[按钮]
 

解决方案

尝试的LinearLayout 而不是 RelativeLayout的将在一个单独的布局上的按钮,并把一个重量上的按钮布局

 的LinearLayout  - 顶层
的LinearLayout与TextViews包埋和重量1
的LinearLayout与滚动型包埋和重量1
的LinearLayout与按钮包埋和1重量
的LinearLayout  - 顶层完成
 

I have a custom dialog with a layout like this:

<RelativeLayout
    xmlns:android="http://schemas.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>

My problem is that the scrollview is that when there is too much text in the scrollview, the buttons below are pushed down out of the dialog. I've been able to prevent it by anchoring the RelativeLayout that contains the buttons to the bottom using android:layout_alignParentBottom="true", but I that stretches the entire dialog to the bottom of the screen when there is less text in the scrollview and I don't want that.

How can I get a layout like this:

[SOME TEXT]
[Scrollable region]
[Buttons]
解决方案

Try LinearLayout instead of the RelativeLayout Put the buttons in a separate layout and put a weight on the buttons layout.

LinearLayout - top level
LinearLayout with TextViews embeded and weight 1
LinearLayout with ScrollView embeded and weight 1
LinearLayout with Buttons embeded and weight 1
LinearLayout - top level finish

这篇关于与滚动型机器人自定义对话框中按下按钮关闭屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 22:50