简体   繁体   中英

Question about table layouts

I'm working pn an andorid app with a tabbed interface and in each tab I want to display text in grid format along with some controls to manipulate the data. Right now I'm using a single table layout but the problem is getting the formatting to work with displaying both the text and controls. The controls end up affecting the width of the text columns. Here's a screenshot: http://www.pikefin.com/img/emulator.png

I was wondering if it's possible to get two table layouts working on the same screen? (I played around with this some but couldn't get it to work)

Or should I be looking at taking a completely different approach?

You should probably be using ListView for your data that's a table. That will break your dependency between the table of data and your buttons. Then use a RelativeLayout to layout the buttons and the ListView within that relative layout.

The biggest reason to do this is memory consumption. If you have more data in your table than you can see then the ListView will only consume the memory needed to display the visible rows. TableLayout will consume memory to display the entire amount of data regardless if it's visible or not. Also ListView gives you selection automatically so you just register for a selection listener on the ListView and that's it. It's written for you. Your tablelayout will require you write it yourself. Also you can have true model backing your UI so you get a specific Object that represents a row in the table.

The tricky part is getting the row to layout properly. For that you'll have to have fixed width columns which you can derive from your existing TableLayout. It sounds like a limitation, but when on mobile you generally don't have a lot of real estate so giving each column a fixed amount ensures everyone layouts as expected.

Well, for the first question. You may find it beneficial to set the width to all of your components to 0px. Then setting the weight to a decimal representation of a percentage (0.2 for 20% for example).

<TextView
    android:layout_width="0px"
    android:layout_height="wrap_content"
    android:layout_weight="0.2"
    android:text="Your Text"
/>

As for your second question, you can have as many TableLayouts in your layout as you wish. It may be that your other TableLayout exists below the current TableLayout. You may need to enclose your TableLayouts within a ScrollLayout system so that you can scroll between them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM