1

我一直在 stackoverflow 中阅读许多关于制作线性布局滚动的帖子,并应用了所有具体建议以使其工作,但它仍然没有显示在左侧。我是 android 新手,不知道我做错了什么。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/scrollView1">
<LinearLayout
    android:id="@+id/expense"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:gravity="start"
    android:orientation="vertical"
    tools:context=".Expense" >

    <LinearLayout
        android:id="@+id/tedsts"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:background="@drawable/rounded"
        android:clickable="true"
        android:weightSum="1.0" >

        <TextView
            android:id="@+id/testffg"
            android:layout_width="1dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight=".30"
            android:text="Matter"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <TextView
            android:id="@+id/tedssss"
            android:layout_width="1dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight=".65"
            android:ellipsize="end"
            android:paddingLeft="10dp"
            android:singleLine="true"
            android:text=""
            android:textAppearance="?android:attr/textAppearanceSmall" />

        <ImageView
            android:layout_width="15dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.05"
            android:src="@drawable/r_arrow" />
    </LinearLayout>

    <TextView
        android:id="@+id/tetxttx"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:layout_marginLeft="0dp"
        android:layout_marginRight="10dp"
        android:ellipsize="marquee"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:marqueeRepeatLimit="marquee_forever"
        android:scrollHorizontally="true"
        android:singleLine="true"  
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textColor="@color/gray_dark"
        android:visibility="invisible" />

    <EditText
        android:id="@+id/teetttsss"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:background="@drawable/rounded_all"
        android:ems="10"
        android:gravity="top"
        android:hint="dgdfgfgf"
        android:inputType="textMultiLine" />

    <LinearLayout
        android:id="@+id/tesssstt"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:background="@drawable/rounded_all_clickable_selector"
        android:clickable="true"
        android:weightSum="1.0" >

        <TextView
            android:id="@+id/yttrree"
            android:layout_width="1dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight=".20"
            android:text="Date"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <TextView
            android:id="@+id/rrrefffe"
            android:layout_width="1dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight=".75"
            android:ellipsize="end"
            android:paddingLeft="10dp"
            android:singleLine="true"
            android:text=""
            android:textAppearance="?android:attr/textAppearanceSmall" />

        <ImageView
            android:layout_width="15dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.05"
            android:src="@drawable/r_arrow" />
    </LinearLayout>

    <RadioButton
        android:id="@+id/dfgrrrrr"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="2dp"
        android:layout_marginTop="5dp"
        android:text="Cost"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <EditText
        android:id="@+id/gergrerrr"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="-4dp"
        android:background="@drawable/rounded_all_clickable"
        android:ems="10"
        android:hint=""
        android:inputType="numberDecimal"
        android:singleLine="true" >
    </EditText>

    <RadioButton
        android:id="@+id/rerreee"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="2dp"
        android:layout_marginTop="5dp"
        android:text="Time"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <EditText
        android:id="@+id/gggrrrrre"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:background="@drawable/roundede"
        android:ems="10"
        android:hint="grrrergg."
        android:inputType="numberDecimal"
        android:singleLine="true"
        android:visibility="gone" >
    </EditText>

    <EditText
        android:id="@+id/65gfhhggf"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="-4dp"
        android:background="@drawable/rounded"
        android:ems="10"
        android:hint=""
        android:inputType="numberDecimal" >
    </EditText>

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

        <TextView
            android:id="@+id/gfhgfhtrhrth"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_marginLeft="50dp"
            android:layout_marginTop="15dp"
            android:visibility="gone" />

        <TextView
            android:id="@+id/ghjjhhhgh"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_marginLeft="30dp"
            android:layout_marginTop="10dp"
            android:layout_toRightOf="@+id/expense_TV_total"
            android:text=""
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <ImageButton
            android:id="@+id/hgjhhghjhg"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:background="@drawable/save_selector" />
    </RelativeLayout>
</LinearLayout>
</ScrollView>
4

5 回答 5

3

用这个 :

<?xml version="1.0" encoding="utf-8"?>
<ScrollView ...>

<LinearLayout ...>

...
...

</LinearLayout>

</ScrollView>

并将高度设置为

android:layout_height="wrap_content"

正如卡拉库里所说

于 2013-08-09T16:01:27.687 回答
2
<?xml version="1.0" encoding="utf-8"?>

<ScrollView  xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="match_parent">

    //Your Main Layout

    <LinearLayout
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:orientation="vertical"     
     android:weightSum="100">

    // First Sub Layout Under Main Layout
       <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal" 
        android:layout_weight="10"
        android:weightSum="100" >

           <TextView
            android:id="@+id/textView1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="TextView" 
            android:layout_weight="70" />

           <EditText
            android:id="@+id/editText1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="30" />

        </LinearLayout>// Finishing First Sub layout 

// Second Sub Layout Under Main Layout
       <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal" 
        android:layout_weight="10"
        android:weightSum="100" >

           <TextView
            android:id="@+id/textView2"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="TextView" 
            android:layout_weight="70" />

           <EditText
            android:id="@+id/editText2"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="30" />

        </LinearLayout>// Finishing Second Sub layout 

similarly for 3rd,4rth,5th sub layouts and so on........

</LinearLayout> // Finishing Main Layout
</ScrollView>   // Finishing ScrollView 
于 2013-08-10T08:34:45.743 回答
1

让 ScrollView 的孩子有android:layout_height="wrap_content"(目前你的有match_parent

于 2013-08-09T15:58:29.307 回答
0

添加

android:layout_width="match_parent"
android:layout_height="match_parent"

到你的根 ScrollView

于 2013-08-10T13:22:15.840 回答
0

我希望这段代码可以帮助你。

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

于 2017-03-20T06:55:18.677 回答