开发者

Setting height of TableRow [duplicate]

This question already has answers here: Android and setting width and height programmatically in dp units (7 answers) Closed 2 years a开发者_如何学Cgo.

I have two types of content for TableRow. One has two lines and the other one. I wish everyone had the same height. I'm trying something like this:

tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, 80));

Any other ideas? And, how can I transform "80" in dp?


you can set the hight by setting the padding

    <TableRow

        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:paddingTop="10dp"
        android:paddingBottom="10dp"
        >

for dynamic

tr.setPadding(0, 12, 0, 12);


You could use two different layouts for the rows and just assign them dynamically in your code. Define the heights in your layouts.


I Solve this with getViewTreeObserver. You must type this method on the tableLayout AND override onGlobalLayout.

Inside this method, you can verify all child's height. Then you can identify Max heigh.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜