我在使用ScrollView时遇到问题。出于某种奇怪的原因,它隐藏了要显示在顶部的内容。我试着给予保证金,填充等,但似乎没有任何效果。这是我的布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" android:background="@drawable/background">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content" android:background="@drawable/titlebar"
android:id="@+id/titlebar">
<TextView android:layout_width="fill_parent" android:id="@+id/textView1"
android:layout_height="fill_parent" android:layout_gravity="center"
android:gravity="center" android:textColor="@color/white"
android:textSize="20dip" android:text="Help"></TextView>
</LinearLayout>
<ScrollView android:layout_height="wrap_content" android:id="@+id/scrollView1"
android:layout_width="fill_parent">
<LinearLayout android:orientation="vertical" android:id="@+id/linearLayout2"
android:gravity="center" android:layout_width="fill_parent"
android:layout_gravity="center" android:layout_height="fill_parent"
android:paddingLeft="10dip" android:paddingRight="5dip">
<ImageView android:layout_height="wrap_content"
android:src="@drawable/icon" android:layout_marginTop="10dip"
android:id="@+id/help_icon" android:layout_width="fill_parent"
android:layout_marginBottom="15dip"></ImageView>
<TextView android:layout_height="wrap_content"
android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed dapibus venenatis suscipit.\n\nCras lacus sem, cursus a dictum sed, condimentum quis urna. Ut vel metus lorem, quis semper lacus. Suspendisse eu urna massa, a blandit mi. "
android:id="@+id/help_text" android:layout_width="wrap_content"
android:textColor="@color/black" android:textSize="15dip"
android:paddingBottom="10dip"></TextView>
</LinearLayout>
</ScrollView>
</LinearLayout>
我的图片隐藏在顶部标题栏后面,只有其底部的一小部分在设备/模拟器中可见。它在Eclipse中显得很好。我正在使用ADT11
提前致谢!
答案 0 :(得分:10)
您好我遇到了同样的问题,经过调查后我找到了解决方案,在您的XML代码中我可以看到您在布局中犯了同样的错误。
问题是您将ScrollView子项(LinearLayout)layout_gravity设置为居中。删除这一行,它应该适合你。
android:layout_gravity="center" //remove this
答案 1 :(得分:0)
我想你想要这样的东西:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/titlebar">
<TextView android:layout_width="fill_parent" android:id="@+id/textView1"
android:layout_height="wrap_content" android:layout_gravity="center"
android:gravity="center" android:textColor="@android:color/white"
android:textSize="20dip" android:text="Help"></TextView>
<ImageView android:layout_height="wrap_content"
android:src="@drawable/icon" android:layout_marginTop="10dip"
android:id="@+id/help_icon" android:layout_width="fill_parent"
android:layout_marginBottom="15dip"></ImageView>
</LinearLayout>
<ScrollView android:layout_height="match_parent" android:id="@+id/scrollView1"
android:layout_width="fill_parent">
<LinearLayout android:orientation="vertical" android:id="@+id/linearLayout2"
android:gravity="center" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="10dip" android:paddingRight="5dip">
<TextView android:layout_height="wrap_content"
android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed dapibus venenatis suscipit.\n\nCras lacus sem, cursus a dictum sed, condimentum quis urna. Ut vel metus lorem, quis semper lacus. Suspendisse eu urna massa, a blandit mi. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed dapibus venenatis suscipit.\n\nCras lacus sem, cursus a dictum sed, condimentum quis urna. Ut vel metus lorem, quis semper lacus. Suspendisse eu urna massa, a blandit mi.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed dapibus venenatis suscipit.\n\nCras lacus sem, cursus a dictum sed, condimentum quis urna. Ut vel metus lorem, quis semper lacus. Suspendisse eu urna massa, a blandit mi.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed dapibus venenatis suscipit.\n\nCras lacus sem, cursus a dictum sed, condimentum quis urna. Ut vel metus lorem, quis semper lacus. Suspendisse eu urna massa, a blandit mi.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed dapibus venenatis suscipit.\n\nCras lacus sem, cursus a dictum sed, condimentum quis urna. Ut vel metus lorem, quis semper lacus. Suspendisse eu urna massa, a blandit mi.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed dapibus venenatis suscipit.\n\nCras lacus sem, cursus a dictum sed, condimentum quis urna. Ut vel metus lorem, quis semper lacus. Suspendisse eu urna massa, a blandit mi."
android:id="@+id/help_text" android:layout_width="wrap_content"
android:textColor="@android:color/white" android:textSize="15sp"
android:paddingBottom="10dip"></TextView>
</LinearLayout>
</ScrollView>
</LinearLayout>
答案 2 :(得分:-2)
将android:layout_weight =“1”添加到您的滚动视图中。它将解决问题。像这样的东西
<ScrollView
android:id="@+id/scroll"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_weight="1" >