Partly missing content problem in ScrollView on an AbsoluteLayout
I have the following layout:
<AbsoluteLayout android:layout_width="fill_parent"
android:id="@+id/absoluteLayout1" android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView android:layout_width="fill_parent" android:layout_x="0dip"
android:id="@+id/textView1" android:layout_height="wrap_content"
android:text="Hello" android:layout_y="0dip"></TextView>
<ScrollView android:layout_x="0dip" android:layout_y="100dip"
android:id="@+id/ScrollView01" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:scrollbars="vertical">
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="0" android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
</LinearLayout>
</ScrollView>
</AbsoluteLayout>
And a short code:
public class LayoutTest extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LinearLayout linerLayout=(LinearLayout)findViewById(R.id.LinearLayout01);
for (int i=1;i<=20;i++) {
Button b=new Button(this);
b.setText("Button "+i);
linerLayout.addView(b,0);
}
}
}
My problem is: I don't see the last two button what I generated!
I figured out this is because the ScrollView has an Y value in: android:layout_y="100dip".
The 100 pixels is exactly the same what I don't see.
If I put an empty view after the buttons with 100 pixels height:
<ScrollView android:layout_x="0dip" android:layout_y="100dip"
android:id="@+id/ScrollView01" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:scrollbars="vertical">
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent" android:layout_height="fill_par开发者_运维百科ent"
android:layout_weight="0" android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView android:layout_width="fill_parent" android:text=""
android:id="@+id/TextViewGap" android:layout_height="100px"
android:background="#ff0000"></TextView>
</LinearLayout>
</ScrollView>
then I see every button. If I set 101 pixels for the TextView then I see a red line at bottom of the screen.
My question is: why I don't see the full content of my ScrollView when it has an Y offset on an AbsoluteLayout?
AbsoluteLayout
is deprecated, anyway it's probably because by setting ScrollView
's height to fill_parent
it gets the height of the whole Layout, not considering the 100dip offset.
Consider using a RelativeLayout
, it often can do in a more efficient way what other complex layouts do (like nested horizontal/vertical LinearLayouts).
精彩评论