【问题标题】:Android: My LinearLayout expands out of its parent scrollviewAndroid:我的 LinearLayout 从其父滚动视图扩展
【发布时间】:2013-09-10 09:24:16
【问题描述】:

谁能帮我处理这段 xml 代码,这是一个打印屏幕: http://flic.kr/p/fKEqmn

这是我的 xml 代码:

    <ScrollView
    android:id="@+id/scrollView1"
    android:layout_marginTop="40dp"

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

   <LinearLayout
   android:id="@+id/LinearLayoutmain"
    android:clipToPadding="true"
   android:layout_width="fill_parent"
   android:layout_height="match_parent"
   android:layout_marginTop="10dp"
   android:orientation="vertical"
   android:scaleType="fitXY" >

    <LinearLayout
    android:id="@+id/LinearLayout01"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="20dp"
    android:layout_marginTop="10dp"
    android:orientation="vertical" >

        <ImageButton
        android:id="@+id/pd"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="110dp"
        android:layout_marginRight="20dp"
        android:adjustViewBounds="true"
        android:background="@null"
        android:maxHeight="30dp"
        android:maxWidth="60dp"
        android:onClick="pod"
        android:scaleType="fitXY"
        android:src="@drawable/podcast" />

        <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:text="My.Podcast section is where students can access voice   " />

        <ImageButton
        android:id="@+id/an"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="110dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="10dp"
        android:adjustViewBounds="true"
        android:background="@null"
        android:maxHeight="30dp"
        android:maxWidth="50dp"
        android:onClick="announce"
        android:scaleType="fitXY"
        android:src="@drawable/announce" />

         <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:text="My.News section contains announcements posted by instructors" />

        <ImageButton
        android:id="@+id/ex"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="110dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="10dp"
        android:adjustViewBounds="true"
        android:background="@null"
        android:maxHeight="30dp"
        android:maxWidth="50dp"
        android:onClick="eksam"
        android:scaleType="fitXY"
        android:src="@drawable/exam" />

         <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:text="My.Exam section contains the schedule of examinations" />

        <ImageButton
        android:id="@+id/kl"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="110dp"
        android:layout_marginRight="20dp"
        android:adjustViewBounds="true"
        android:background="@null"
        android:maxHeight="30dp"
        android:maxWidth="50dp"
        android:onClick="kalendaryo"
        android:scaleType="fitXY"
        android:src="@drawable/calendar" />

        <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:text="My.Calendar section has the schedule of different University " />

        <ImageButton
        android:id="@+id/cl"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="110dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="10dp"
        android:adjustViewBounds="true"
        android:background="@null"
        android:maxHeight="30dp"
        android:maxWidth="50dp"
        android:onClick="klas"
        android:scaleType="fitXY"
        android:src="@drawable/klase" />

        <TextView
        android:id="@+id/textView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:text="My.Class section contains the users different class schedules" />

       <ImageButton
        android:id="@+id/gr"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="110dp"
        android:layout_marginRight="20dp"
        android:adjustViewBounds="true"
        android:background="@null"
        android:maxHeight="30dp"
        android:maxWidth="50dp"
        android:onClick="grupo"
        android:scaleType="fitXY"
        android:src="@drawable/group" />

        <TextView
        android:id="@+id/textView6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:text="My.Groups section lists all the groups that the user belongs"  />

        <ImageButton
         android:id="@+id/lc"
         android:layout_width="50dp"
         android:layout_height="wrap_content"
         android:layout_marginLeft="110dp"
         android:layout_marginRight="20dp"
         android:layout_marginTop="10dp"
         android:adjustViewBounds="true"
         android:background="@null"
         android:maxHeight="30dp"
         android:maxWidth="50dp"
         android:onClick="lectures"
         android:scaleType="fitXY"
         android:src="@drawable/lec" />

        <TextView
         android:id="@+id/textView7"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_marginTop="10dp"
         android:text="My.Lectureshare contains files that were posted by the       />

        <ImageButton
         android:id="@+id/post"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="110dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="10dp"
        android:adjustViewBounds="true"
        android:background="@null"
        android:maxHeight="30dp"
        android:maxWidth="50dp"
        android:onClick="lecpost"
        android:scaleType="fitXY"
        android:src="@drawable/post" />

     <TextView
        android:id="@+id/textView8"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:text="My.Post is were instructors are capable to post files  class" />

     </LinearLayout>





      </LinearLayout>


     </ScrollView>

所以基本上我希望线性布局适合它的父滚动视图。我已经将它的高度设置为 match_parent 但它仍然超出范围

【问题讨论】:

  • 还是不行@SKT
  • 还是不行@shiju B
  • ScrollView 的目的是给它的孩子它可能想要的空间。如果您需要使子LinearLayout 与屏幕一样大,则删除ScrollView 或将`LinearLayout 的高度设置为与屏幕的高度完全相同。
  • @Luksprog 这里是 flickr.com/photos/64167089@N03/9683198109 的屏幕截图,尽管它是可滚动的,但当我向下滚动时它看起来像这样
  • @Chad 我复制粘贴了您的布局并尝试了它。它对我来说看起来不错,并且可以缩放到窗口的底部。您可以尝试在滚动视图标签中使用 android:fillViewport="true" 吗?

标签: android android-layout android-linearlayout boundary


【解决方案1】:

滚动视图被设计为具有超出屏幕高度的内容,从而使其可滚动。我认为这就是您首先使用滚动视图的原因。

如果您希望能够在设计器中看到您的所有子 LinearLayout,您可以从 Nexus S 更改设备视图(在您的屏幕截图中设置)并选择例如 10.1 平板电脑视图。这不会影响设计在您手机上的外观,只会为您提供更多的屏幕空间进行设计。

【讨论】:

  • 这是 flickr.com/photos/64167089@N03/9683198109 的屏幕截图,尽管它是可滚动的,但当我向下滚动时它看起来像这样
【解决方案2】:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="5dp" >

    <LinearLayout
        android:id="@+id/LinearLayout01"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="vertical" >

        <ImageButton
            android:id="@+id/pd"
            android:layout_width="50dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:adjustViewBounds="true"
            android:maxHeight="30dp"
            android:maxWidth="60dp"
            android:onClick="pod"
            android:scaleType="fitXY"
            android:src="@drawable/ic_launcher" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:text="My.Podcast section is where students can access voice   " />

        <ImageButton
            android:id="@+id/an"
            android:layout_width="50dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:adjustViewBounds="true"
            android:maxHeight="30dp"
            android:maxWidth="50dp"
            android:onClick="announce"
            android:scaleType="fitXY"
            android:src="@drawable/ic_launcher" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:text="My.News section contains announcements posted by instructors" />

        <ImageButton
            android:id="@+id/ex"
            android:layout_width="50dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:adjustViewBounds="true"
            android:maxHeight="30dp"
            android:maxWidth="50dp"
            android:onClick="eksam"
            android:scaleType="fitXY"
            android:src="@drawable/ic_launcher" />

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:text="My.Exam section contains the schedule of examinations" />

        <ImageButton
            android:id="@+id/kl"
            android:layout_width="50dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:adjustViewBounds="true"
            android:maxHeight="30dp"
            android:maxWidth="50dp"
            android:onClick="kalendaryo"
            android:scaleType="fitXY"
            android:src="@drawable/ic_launcher" />

        <TextView
            android:id="@+id/textView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:text="My.Calendar section has the schedule of different University " />

        <ImageButton
            android:id="@+id/cl"
            android:layout_width="50dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:adjustViewBounds="true"
            android:maxHeight="30dp"
            android:maxWidth="50dp"
            android:onClick="klas"
            android:scaleType="fitXY"
            android:src="@drawable/ic_launcher" />

        <TextView
            android:id="@+id/textView5"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:text="My.Class section contains the users different class schedules" />

        <ImageButton
            android:id="@+id/gr"
            android:layout_width="50dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:adjustViewBounds="true"
            android:maxHeight="30dp"
            android:maxWidth="50dp"
            android:onClick="grupo"
            android:scaleType="fitXY"
            android:src="@drawable/ic_launcher" />

        <TextView
            android:id="@+id/textView6"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:text="My.Groups section lists all the groups that the user belongs" />

        <ImageButton
            android:id="@+id/lc"
            android:layout_width="50dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:adjustViewBounds="true"
            android:maxHeight="30dp"
            android:maxWidth="50dp"
            android:onClick="lectures"
            android:scaleType="fitXY"
            android:src="@drawable/ic_launcher" />

        <TextView
            android:id="@+id/textView7"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:onClick="lecpost"
            android:text="My.Lectureshare contains files that were posted by the" />

        <ImageButton
            android:id="@+id/post"
            android:layout_width="50dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:adjustViewBounds="true"
            android:maxHeight="30dp"
            android:maxWidth="50dp"
            android:onClick="lecpost"
            android:scaleType="fitXY"
            android:src="@drawable/ic_launcher" />

        <TextView
            android:id="@+id/textView8"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:text="My.Post is were instructors are capable to post files  class" />
    </LinearLayout>

</ScrollView>

// this my out put
![enter image description here][1]

【讨论】:

  • 先生,我已经尝试过您修改过的代码,但是当我运行应用程序时,滚动视图不允许我滚动到最后一个文本视图,即 textview8
猜你喜欢
  • 2013-03-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-27
  • 1970-01-01
相关资源
最近更新 更多