I am trying to find out how I can add an item (from xml drawable/workaround_item.xml) in a LinearLayout that is vertically aligned.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="100dip"
android:layout_marginTop="5dip"
android:paddingTop="5dip"
android:paddingBottom="5dip"
android:orientation="horizontal">
<LinearLayout
android:layout_width="100dp"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_alignParentLeft="true"
android:gravity="center_vertical">
<ImageView
android:id="@+id/home_image"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" />
<TextView
android:id="@+id/home_team"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:textStyle="bold"
android:textSize="12sp"
android:textColor="#fff"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="center_vertical"
android:layout_centerHorizontal="true">
<TextView
android:id="@+id/game_cship"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal|center_vertical"
android:textStyle="bold"
android:textSize="10sp"/>
<TextView
android:id="@+id/game_score"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:textStyle="bold"
android:textColor="#fff" android:textSize="24sp"/>
<TextView
android:id="@+id/game_date"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:textStyle="bold"
android:textSize="10sp"/>
</LinearLayout>
<LinearLayout
android:layout_width="100dp"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="center_vertical"
android:layout_alignParentRight="true">
<ImageView
android:id="@+id/away_image"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" />
<TextView
android:id="@+id/away_team"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:textStyle="bold"
android:textSize="12sp"
android:textColor="#fff" />
</LinearLayout>
</RelativeLayout>
At the beginning I was trying to use a ListView but as far I as know there is a bug using listview inside a scrollview. I was doing this because I have more components on the view that should be scrolled together with the list view. So I decided to remove the listview and implement a simple linear layout where i will be adding each element below other and so on.
The layout for the activity is as follow (layout/workaround.xml) and I would like to start adding the elements below the top bar.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="@+id/linearid" >
</LinearLayout>
That's my Java code:
public class DemoActivity3 extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.workaround);
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout ll = (LinearLayout) this.findViewById(R.id.linearid);
for(int i = 1; i< 15; i++) {
View item = inflater.inflate(R.layout.workaround_item, null);
TextView x = (TextView) item.findViewById(R.id.game_score);
x.setText("Score" + i);
TextView ht = (TextView) item.findViewById(R.id.home_team);
ht.setText("HomeTeam" + i);
TextView at = (TextView) item.findViewById(R.id.away_team);
at.setText("AwayTeam"+i);
ImageView hi = (ImageView) item.findViewById(R.id.home_image);
hi.setImageResource(R.drawable.gremio);
ImageView ai = (ImageView) item.findViewById(R.id.away_image);
ai.setImageResource(R.drawable.goias);
ll.addView(item,ViewGroup.LayoutParams.WRAP_CONTENT);
}
}
That's the result I am getting: http://twitpic.com/3562yu
Does Android allow us to do this? If so, Hoe can I add the elements and set their values? (this layout will be displaying results of soccer games).