Well, my question is quite simple.
I am beginning Android programming and I am programming a simple calendar app.
My main layout is like this (There's more above the RelativeLayout, but I think it's not important):
<RelativeLayout
android:id
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/header" >
<GridView
android:id="@+id/month_days"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="7"
android:stretchMode="columnWidth"
android:columnWidth="60dp"
android:horizontalSpacing="1dp"
android:verticalSpacing="1dp" >
</GridView>
</RelativeLayout>
I want the GridView to use every single pixel in the Layout, in height and in width. I could adjust de columnWidth property to gain that, but I don't know how to do this with height.
I was thinking in getting the RelativeLayout dimensions (height particularly), and dividing it by 6, which is the number of rows I want... But I'm not sure if this is correct neither how to do this.
Thanks in advance!
Edit:
Something I did not say: I have a custom adapter to populate the GridView and its properties. Here's the code.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/actual_month_day" >
<TextView
android:id="@+id/day_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
</TextView>
</RelativeLayout>
If I change android:layout_height="65dp"
, for example, it makes the cell bigger, which is something similar to what I want, but it does not cover the entire screen. If I write a bigger value I need to scroll to see the whole grid.
The problem is the value. I want the "65dp" to be dynamic and change depending on the free space in the screen.
If it helps, here's the getView()
in my adapter.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v;
TextView actualDay;
if (convertView == null) {
v = new View(c);
v = inflater.inflate(R.layout.calendar_day_2, parent, false);
actualDay = (TextView) v.findViewById(R.id.day_2);
actualDay.setText(days[position]);
if(!isActualMonth(position)) v.setBackgroundColor(c.getResources().getColor(R.color.not_actual_month_day));
} else {
v = (View) convertView;
}
return v;
}
I think that I have to calculate the Layout's remaining space in the getView()
code, but I don't know how.
I've tried adding actualDay.setHeight(parent.getHeight()/6);
but it didn't help me too much. The cell's height is ok, but it scrolls up and then everything disappears. After that, I set android:scrollbars="none"
, but still nothing.
I do not know what's the problem here. Maybe the logic is fine, but the property of the scrollbar is not what I need. Sorry if it is all a bit messy, but I wanted to tell you the things I've tried.
Thank you again.