How can I size columns in a gridlayout?
up vote
1
down vote
favorite
I'm building a GridLayout.
I have 8 columns.
I want the first TextView to span 6 cols and display the text on 2 lines.
I want the next TextView to span 1 col and to display a Number from 1 to 10.
Finally the next TextView display the following text "/10"
So far I've achieved what I want, but not so much with the alignments.
Code:
<GridLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnCount="7"
android:orientation="horizontal"
android:rowCount="8">
<TextView
android:minLines="2"
android:gravity="center_vertical"
android:layout_row="1"
android:layout_columnSpan="5"
android:layout_columnWeight="4"
android:layout_gravity="fill_horizontal"
android:id="@+id/qol1"
android:text="Avoir du temps pour moi" />
<TextView
android:layout_columnSpan="1"
android:layout_gravity="fill_horizontal"
android:id="@+id/score_qol1"
android:text="6"
style="@android:style/TextAppearance.DeviceDefault.Large"
android:gravity="right" />
<TextView
android:layout_columnSpan="1"
android:layout_gravity="fill_horizontal"
android:id="@+id/score_qol1_10"
android:text="/10"
android:gravity="right" />
</GridLayout>
The result is the following:
As you can Imagine, I'd like the last cell to wrap its content, the middle one to be aligned on the left and the first cell to take all the space available, according to the mockup I have:
I know that the last 2 cells will always take approximately the same space. I don't wan't to use fixed sizes because of the diversity of screen resolutions.
I thought that layout_columnWeight would be the solution, but it does not work.
android android-gridlayout
add a comment |
up vote
1
down vote
favorite
I'm building a GridLayout.
I have 8 columns.
I want the first TextView to span 6 cols and display the text on 2 lines.
I want the next TextView to span 1 col and to display a Number from 1 to 10.
Finally the next TextView display the following text "/10"
So far I've achieved what I want, but not so much with the alignments.
Code:
<GridLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnCount="7"
android:orientation="horizontal"
android:rowCount="8">
<TextView
android:minLines="2"
android:gravity="center_vertical"
android:layout_row="1"
android:layout_columnSpan="5"
android:layout_columnWeight="4"
android:layout_gravity="fill_horizontal"
android:id="@+id/qol1"
android:text="Avoir du temps pour moi" />
<TextView
android:layout_columnSpan="1"
android:layout_gravity="fill_horizontal"
android:id="@+id/score_qol1"
android:text="6"
style="@android:style/TextAppearance.DeviceDefault.Large"
android:gravity="right" />
<TextView
android:layout_columnSpan="1"
android:layout_gravity="fill_horizontal"
android:id="@+id/score_qol1_10"
android:text="/10"
android:gravity="right" />
</GridLayout>
The result is the following:
As you can Imagine, I'd like the last cell to wrap its content, the middle one to be aligned on the left and the first cell to take all the space available, according to the mockup I have:
I know that the last 2 cells will always take approximately the same space. I don't wan't to use fixed sizes because of the diversity of screen resolutions.
I thought that layout_columnWeight would be the solution, but it does not work.
android android-gridlayout
1
have you tried looking into constraint layout, it is advanced has more features codelabs.developers.google.com/codelabs/constraint-layout/…
– Karan Mer
Nov 21 at 12:36
I was unsure it would be available with Xamarin.Android, but it is. Will do.
– Olivier MATROT
Nov 21 at 13:10
I guess you choose aGridLayout
thinking it would be easier to build the layout. But your layout is so simple that it becomes hard. You could achieve this by usingConstraintLayout
orLinearLayout
settingweight
attibute in each view.
– Giovanne
Nov 21 at 13:28
1
@Giovanne I ended up using a LinearLayout inside a row of the GridLayout and this is working fine.
– Olivier MATROT
Nov 22 at 12:56
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I'm building a GridLayout.
I have 8 columns.
I want the first TextView to span 6 cols and display the text on 2 lines.
I want the next TextView to span 1 col and to display a Number from 1 to 10.
Finally the next TextView display the following text "/10"
So far I've achieved what I want, but not so much with the alignments.
Code:
<GridLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnCount="7"
android:orientation="horizontal"
android:rowCount="8">
<TextView
android:minLines="2"
android:gravity="center_vertical"
android:layout_row="1"
android:layout_columnSpan="5"
android:layout_columnWeight="4"
android:layout_gravity="fill_horizontal"
android:id="@+id/qol1"
android:text="Avoir du temps pour moi" />
<TextView
android:layout_columnSpan="1"
android:layout_gravity="fill_horizontal"
android:id="@+id/score_qol1"
android:text="6"
style="@android:style/TextAppearance.DeviceDefault.Large"
android:gravity="right" />
<TextView
android:layout_columnSpan="1"
android:layout_gravity="fill_horizontal"
android:id="@+id/score_qol1_10"
android:text="/10"
android:gravity="right" />
</GridLayout>
The result is the following:
As you can Imagine, I'd like the last cell to wrap its content, the middle one to be aligned on the left and the first cell to take all the space available, according to the mockup I have:
I know that the last 2 cells will always take approximately the same space. I don't wan't to use fixed sizes because of the diversity of screen resolutions.
I thought that layout_columnWeight would be the solution, but it does not work.
android android-gridlayout
I'm building a GridLayout.
I have 8 columns.
I want the first TextView to span 6 cols and display the text on 2 lines.
I want the next TextView to span 1 col and to display a Number from 1 to 10.
Finally the next TextView display the following text "/10"
So far I've achieved what I want, but not so much with the alignments.
Code:
<GridLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnCount="7"
android:orientation="horizontal"
android:rowCount="8">
<TextView
android:minLines="2"
android:gravity="center_vertical"
android:layout_row="1"
android:layout_columnSpan="5"
android:layout_columnWeight="4"
android:layout_gravity="fill_horizontal"
android:id="@+id/qol1"
android:text="Avoir du temps pour moi" />
<TextView
android:layout_columnSpan="1"
android:layout_gravity="fill_horizontal"
android:id="@+id/score_qol1"
android:text="6"
style="@android:style/TextAppearance.DeviceDefault.Large"
android:gravity="right" />
<TextView
android:layout_columnSpan="1"
android:layout_gravity="fill_horizontal"
android:id="@+id/score_qol1_10"
android:text="/10"
android:gravity="right" />
</GridLayout>
The result is the following:
As you can Imagine, I'd like the last cell to wrap its content, the middle one to be aligned on the left and the first cell to take all the space available, according to the mockup I have:
I know that the last 2 cells will always take approximately the same space. I don't wan't to use fixed sizes because of the diversity of screen resolutions.
I thought that layout_columnWeight would be the solution, but it does not work.
android android-gridlayout
android android-gridlayout
edited Nov 21 at 12:28
Aniruddh Parihar
2,1431927
2,1431927
asked Nov 21 at 12:27
Olivier MATROT
1,25021840
1,25021840
1
have you tried looking into constraint layout, it is advanced has more features codelabs.developers.google.com/codelabs/constraint-layout/…
– Karan Mer
Nov 21 at 12:36
I was unsure it would be available with Xamarin.Android, but it is. Will do.
– Olivier MATROT
Nov 21 at 13:10
I guess you choose aGridLayout
thinking it would be easier to build the layout. But your layout is so simple that it becomes hard. You could achieve this by usingConstraintLayout
orLinearLayout
settingweight
attibute in each view.
– Giovanne
Nov 21 at 13:28
1
@Giovanne I ended up using a LinearLayout inside a row of the GridLayout and this is working fine.
– Olivier MATROT
Nov 22 at 12:56
add a comment |
1
have you tried looking into constraint layout, it is advanced has more features codelabs.developers.google.com/codelabs/constraint-layout/…
– Karan Mer
Nov 21 at 12:36
I was unsure it would be available with Xamarin.Android, but it is. Will do.
– Olivier MATROT
Nov 21 at 13:10
I guess you choose aGridLayout
thinking it would be easier to build the layout. But your layout is so simple that it becomes hard. You could achieve this by usingConstraintLayout
orLinearLayout
settingweight
attibute in each view.
– Giovanne
Nov 21 at 13:28
1
@Giovanne I ended up using a LinearLayout inside a row of the GridLayout and this is working fine.
– Olivier MATROT
Nov 22 at 12:56
1
1
have you tried looking into constraint layout, it is advanced has more features codelabs.developers.google.com/codelabs/constraint-layout/…
– Karan Mer
Nov 21 at 12:36
have you tried looking into constraint layout, it is advanced has more features codelabs.developers.google.com/codelabs/constraint-layout/…
– Karan Mer
Nov 21 at 12:36
I was unsure it would be available with Xamarin.Android, but it is. Will do.
– Olivier MATROT
Nov 21 at 13:10
I was unsure it would be available with Xamarin.Android, but it is. Will do.
– Olivier MATROT
Nov 21 at 13:10
I guess you choose a
GridLayout
thinking it would be easier to build the layout. But your layout is so simple that it becomes hard. You could achieve this by using ConstraintLayout
or LinearLayout
setting weight
attibute in each view.– Giovanne
Nov 21 at 13:28
I guess you choose a
GridLayout
thinking it would be easier to build the layout. But your layout is so simple that it becomes hard. You could achieve this by using ConstraintLayout
or LinearLayout
setting weight
attibute in each view.– Giovanne
Nov 21 at 13:28
1
1
@Giovanne I ended up using a LinearLayout inside a row of the GridLayout and this is working fine.
– Olivier MATROT
Nov 22 at 12:56
@Giovanne I ended up using a LinearLayout inside a row of the GridLayout and this is working fine.
– Olivier MATROT
Nov 22 at 12:56
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53412041%2fhow-can-i-size-columns-in-a-gridlayout%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
have you tried looking into constraint layout, it is advanced has more features codelabs.developers.google.com/codelabs/constraint-layout/…
– Karan Mer
Nov 21 at 12:36
I was unsure it would be available with Xamarin.Android, but it is. Will do.
– Olivier MATROT
Nov 21 at 13:10
I guess you choose a
GridLayout
thinking it would be easier to build the layout. But your layout is so simple that it becomes hard. You could achieve this by usingConstraintLayout
orLinearLayout
settingweight
attibute in each view.– Giovanne
Nov 21 at 13:28
1
@Giovanne I ended up using a LinearLayout inside a row of the GridLayout and this is working fine.
– Olivier MATROT
Nov 22 at 12:56