开发者

Android layoutparms scrollvew height

I have a tableview inside of a scrollview. I want to res开发者_运维知识库erve space for a listview 2/3 of the screen. I am getting the height of the screen, and will divide that in 2/3 and set the height of the ScrollView. But even with manually x and y numbers its blowing up.

App is crashing when I set the ScrollView width and height like this:

        ScrollView sv = (ScrollView)findViewById(R.id.usdScroll);

    ScrollView.LayoutParams layoutParams = new ScrollView.LayoutParams( -1, 550);
    sv.setLayoutParams(layoutParams);

Any ideas what I did wrong?


You can use the layout_weight attribute to specify how much of a view the specific component will use, e.g. android:layout_weight=2. So for your listView set a weight of 1 and a weight of 2 for your tableview, I think. Anyway, play with the weight setting and you can split the view in any ratio you like.


LayoutParams is used to tell their parents how they want to be laid out. So the layout param's type which you set to must match its parent class type exactly.

and here is a better solution, using layout_weight instead. Try this please

<ScrollView android:layout_weight="1" ........></ScrollView>
<ListView  android:layout_weight="2" ........></ListView>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜