简体   繁体   English

ScrollView内的RelativeLayout-Android

[英]RelativeLayout inside of ScrollView - Android

I am changing my whole layout for this activity from a TableLayout to RelativeLayout for various reasons. 由于各种原因,我正在将此活动的整个布局从TableLayout更改为RelativeLayout I have 10 "rows" I want inside of this RelativeLayout but right now I am just trying to get one row working. 我想在此RelativeLayout放入10个“行”,但是现在我只是想让一行工作。 After that 1 row is working, I will implement the other 9. 在那一行工作之后,我将实现另外9行。

There are 4 columns in each row and right now only the first column is displaying and not the last 3. Below is the code and screenshot. 每行有4列,现在仅显示第一列,而不显示最后3列。以下是代码和屏幕截图。 The "red x" is the first column that is displaying. “红色x”是显示的第一列。

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/tableLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretchColumns="1"
    android:shrinkColumns="0"
    android:orientation="vertical"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:paddingTop="70dp"
    android:paddingBottom="70dp"
    android:background="@drawable/scroll" >    

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="20" >

        <TableRow
            android:id="@+id/header"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1" >

            <TextView
                android:id="@+id/category"
                android:layout_height="wrap_content"
                android:layout_width="0px"
                android:layout_weight="1"
                android:textStyle="bold"
                android:textSize="15sp"
                android:paddingTop="10dp"
                android:gravity="center_horizontal" />

            <TableLayout
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight="1" >

                <TableRow
                    android:layout_width="0dip"
                    android:layout_height="wrap_content"
                    android:layout_weight="1" >

                    <TextView
                        android:id="@+id/points"
                        android:layout_width="0dip"
                        android:layout_height="wrap_content"
                        android:layout_weight=".25"
                        android:textSize="9sp"
                        android:gravity="left" 
                        android:textStyle="bold" />
                </TableRow>

                <TableRow
                    android:layout_width="0dip"
                    android:layout_height="wrap_content"
                    android:layout_weight="1" >

                    <TextView
                        android:id="@+id/percentage"
                        android:layout_width="0dip"
                        android:layout_height="wrap_content"
                        android:layout_weight=".3"
                        android:textSize="9sp"
                        android:gravity="left"
                        android:textStyle="bold" />
                </TableRow>

                <TableRow
                    android:layout_width="0dip"
                    android:layout_height="wrap_content"
                    android:layout_weight="1" >

                    <TextView
                        android:id="@+id/total_score"
                        android:layout_width="0dip"
                        android:layout_height="wrap_content"
                        android:layout_weight=".45"
                        android:textSize="9sp"
                        android:gravity="left"
                        android:textStyle="bold" />
                </TableRow>
            </TableLayout>
        </TableRow>

        <View 
            android:layout_width="fill_parent"
            android:layout_height="1dp"       
            android:background="#000001" />

        <TableRow
            android:id="@+id/row3"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1" >

            <TextView
                android:id="@+id/imageColumn"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight="0" />

            <TextView
                android:id="@+id/questionColumn"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight=".45"
                android:textSize="10sp"
                android:textStyle="bold|italic"
                android:gravity="center_vertical" />

            <TextView
                android:id="@+id/answerColumn"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight=".3"
                android:textSize="10sp"
                android:textStyle="bold|italic"
                android:gravity="center_vertical" />

            <TextView
                android:id="@+id/verseColumn"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight=".25"
                android:textSize="10sp"
                android:textStyle="bold|italic"
                android:gravity="center_vertical" />
        </TableRow>
    </TableLayout>

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="65"
        android:fillViewport="true" >

        <RelativeLayout 
            android:layout_width="fill_parent"   
            android:layout_height="wrap_content"> 

            <ImageView 
                android:id="@+id/q1Image"
                android:layout_width="10dp"
                android:layout_height="10dp"  /> 

            <TextView 
                android:id="@+id/q1Question"
                android:layout_width="0dip"
                android:layout_height="wrap_content" /> 

            <TextView 
                android:id="@+id/q1Answer"
                android:layout_width="0dip"
                android:layout_height="wrap_content"   
                android:layout_toRightOf="@id/q1Question"  /> 

            <TextView 
                android:id="@+id/q1Verse"
                android:layout_width="0dip"
                android:layout_height="wrap_content"   
                android:layout_toRightOf="@id/q1Answer"  /> 
        </RelativeLayout>
    </ScrollView>

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="15" >

        <TableRow
            android:id="@+id/row14"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:stretchColumns="0,1" >

            <Button 
                android:id="@+id/mainmenuBtn"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:textSize="7sp" />

            <Button 
                android:id="@+id/highscoresBtn"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:textSize="7sp" />
            <Button 
                android:id="@+id/playBtn"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:textSize="7sp" />
        </TableRow>
    </TableLayout>
</LinearLayout>

在此处输入图片说明

If I read it correctly and you are referring to this ScrollView: 如果我没看错,而您指的是此ScrollView:

<ScrollView
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="65"
        android:fillViewport="true" >

        <RelativeLayout 
            android:layout_width="fill_parent"   
            android:layout_height="wrap_content"> 

            <ImageView 
                android:id="@+id/q1Image"
                android:layout_width="10dp"
                android:layout_height="10dp"  /> 

            <TextView 
                android:id="@+id/q1Question"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@id/q1Image"   /> 

            <TextView 
                android:id="@+id/q1Answer"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"   
                android:layout_toRightOf="@id/q1Question"  /> 

            <TextView 
                android:id="@+id/q1Verse"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"   
                android:layout_toRightOf="@id/q1Answer"  /> 
        </RelativeLayout>
    </ScrollView>

Your TextView's layout_width was set to 0dip when you need a wrap_content or static width. 当您需要wrap_content或静态宽度时,您的TextView的layout_width设置为0dip。 Also your TextView q1Question was not attached to the right of ImageView q1Image. 同样,您的TextView q1Question也未附加在ImageView q1Image的右侧。 Unless of course you wanted it stacked ontop of the ImageView. 当然,除非您希望将其堆叠在ImageView的顶部。

Looks like your views inside of your imageView have a width of 0dip and no weight. 看起来您在imageView内部的视图的宽度为0dip,没有权重。 Could you correct that ? 你能纠正吗?

Also, you could remove the weights on the TableRows and set them to match_parent. 另外,您可以删除TableRows上的权重并将其设置为match_parent。

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

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