简体   繁体   English

当我在其中添加滚动视图时,文本视图的权重属性不会影响活动?

[英]Weight property for text-view not effecting in activity when I put scroll-view in it?

My XML file I have Problem with the text view weight Property. 我的XML文件在文本视图权重属性方面有问题。 I added Weight property without scroll view at that time it work properly but when I add scroll view that time its not working properly. 我当时添加了不带滚动视图的Weight属性,但是它正常工作,但是当我添加滚动视图时,它却无法正常工作。

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#fff" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <WebView
            android:id="@+id/webView1"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

        <TextView
            android:id="@+id/txtO1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="Large Text"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="#000" />

        <TextView
            android:id="@+id/txtO2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="Large Text"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="#000" />

        <TextView
            android:id="@+id/txtO3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="Large Text"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="#000" />

        <TextView
            android:id="@+id/txtO4"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="Large Text"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="#000" />

        <TextView
            android:id="@+id/txtO5"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="Large Text"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="#000" />

        <TextView
            android:id="@+id/txtAns"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="Large Text"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="#000" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1" <---- Problem is here
            android:text="TextView" />

        <Button
            android:id="@+id/btnAns"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Answer" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <Button
                android:id="@+id/btnPre"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Previous" />

            <Button
                android:id="@+id/btnNxt"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Next" />
        </LinearLayout>
    </LinearLayout>

</ScrollView>

Solution Acceptable Thank You 解决方案可以接受,谢谢

Use android:fillViewport="true" in your Scrollview . Scrollview使用android:fillViewport="true"

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#fff"
    android:fillViewport="true" >

Try like this. 尝试这样。

Actually it is the scrollView which is not getting full height and for that you should add the 实际上是scrollView并没有达到全高,为此,您应该添加

android:fillViewport="true"

in your scrollview. 在您的滚动视图中。 You can just checkout my answer here 你可以在这里签出我的答案

Android TableLayout inside ScrollView ScrollView中的Android TableLayout

and just try out this xml ,I have checked it on my machine:-- 只是尝试这个xml,我已经在我的机器上检查了它:-

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:fillViewport="true" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <WebView
        android:id="@+id/webView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/txtO1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#000" />

    <TextView
        android:id="@+id/txtO2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#000" />

    <TextView
        android:id="@+id/txtO3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#000" />

    <TextView
        android:id="@+id/txtO4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#000" />

    <TextView
        android:id="@+id/txtO5"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#000" />

    <TextView
        android:id="@+id/txtAns"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#000" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="TextView" />

    <Button
        android:id="@+id/btnAns"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Answer" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/btnPre"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Previous" />

        <Button
            android:id="@+id/btnNxt"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Next" />
    </LinearLayout>
</LinearLayout>

</ScrollView>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM