Fel*_*lix 362 android android-layout
我有一个LinearLayout里面ScrollView有android:layout_height="fill_parent",但它并没有扩展到的最大高度ScrollView.我的布局看起来像:
level layout layout_width layout_height
1 LinearLayout fill_parent fill_parent
2 LinearLayout fill_parent wrap_content
3 (some irrelevant stuff)
2 ScrollView fill_parent fill_parent <-- this expands full height
3 LinearLayout fill_parent fill_parent <-- this does not (has orientation=vertical)
(following stuff probably are irrelevant, but just to be sure:)
4 TextView fill_parent fill_parent
4 LinearLayout fill_parent wrap_content
Run Code Online (Sandbox Code Playgroud)
我可以看到LinearLayout它没有扩展整个高度,ScrollView因为在Eclipse中Android Layout Editor,如果我选择ScrollView(在"大纲"面板中)它会突出显示一个红色边框,将屏幕填充到底部但是当我选择LinearLayout它的高亮显示时不会扩展到屏幕的底部.我怎么能这样做?
我想要达到的效果是在它下面有一些文字和一个按钮(在第LinearLayout4级里面只有一个按钮).文本可能足够大,需要滚动条,在这种情况下,我希望用户必须向下滚动才能看到按钮.如果文本不够大,滚动条,我希望LinearLayout包含按钮粘在屏幕的底部.
起初我以为我不应该发布完整的XML,因为在一个问题中看到大量的代码通常是一个转折点.但是,它似乎有必要,所以这里是完整的布局.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/video_layout"
android:focusable="true"
style="@style/VideoLayout">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:foreground="@android:drawable/ic_media_play"
android:foregroundGravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/video_thumb"
android:padding="5dip"
android:background="#454545"/>
</FrameLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:focusable="true"
style="@style/VideoTitle"
android:id="@+id/video_title"
android:layout_gravity="center"
android:layout_weight="1"/>
</LinearLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<!-- this ScrollView expands the full height of the screen.
However, the next LinearLayout does not expand the full height of the ScrollView -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:layout_gravity="fill"
android:orientation="vertical"
android:id="@+id/info_layout">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/info_body"
style="@style/InfoText"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
style="@android:style/ButtonBar">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:text="@string/button_readmore"
android:id="@+id/btn_read_more"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
目前我已经采取android:layout_gravity="bottom"了问题LinearLayout,这使得按钮无论如何都会粘在屏幕的底部.但这也使文本粘在屏幕的底部,这不是我所追求的.
更新:刮擦,android:layout_gravity="bottom"使得ScrollView无法滚动.其他想法?
Fel*_*lix 944
最后我自己找到了解决方案.问题不在于LinearLayout,而是ScrollView(似乎很奇怪,考虑到ScrollView 正在扩大的事实,而事实LinearLayout并非如此).
该解决方案是使用android:fillViewport="true"的ScrollView.
Har*_*560 21
我知道这个帖子很老了,对于那些不想使用的人,android:fillViewport="true"因为它有时候不会调出键盘上方的edittext.使用相对布局而不是LinearLayout它解决了目的.
你能提供你的布局xml吗?这样做可以让人们以最小的努力重新创建问题.
你可能需要设置
android:layout_weight="1"
Run Code Online (Sandbox Code Playgroud)
对于要扩展的项目
小智 7
解决方案是使用
android:fillViewport="true"
在滚动视图上,此外尝试使用
"wrap_content"而不是"fill_parent"作为"fill_parent"
现在已弃用。
| 归档时间: |
|
| 查看次数: |
140344 次 |
| 最近记录: |