안드로이드

 

 

 

 

 

 

 

 

 

 

 

 

 

 

그리드 뷰

 

 

 

 

 

 

 

 

 

 

class MainActivity

package org.androidtown.mygrid;

import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    GridView gridView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        gridView=(GridView)findViewById(R.id.grid1);
        SingerAdaper adaper=new SingerAdaper();
        gridView.setAdapter(adaper);
    }

    class SingerAdaper extends BaseAdapter{

        String[] names ={"걸스데이", "소녀시대", "씨스타", "티아라",
                        "SES", "오마이걸", "애프터스쿨"};



        @Override
        public int getCount() {
            return names.length;
        }

        @Override
        public Object getItem(int position) {
            return names[position];
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {

            TextView view=new TextView(getApplicationContext());
            view.setText(names[position]);
            view.setTextSize(20.0f);
            view.setTextColor(Color.BLACK);

            return view;
        }
    }


}

 

R.layout.activity_main

<?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:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="org.androidtown.mygrid.MainActivity">

    <Button
        android:text="Button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:id="@+id/button" />

    <GridView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/button"
        android:id="@+id/grid1"
        android:numColumns="3"
        />


</RelativeLayout>

 

 

 

 

 

 

android

 

about author

PHRASE

Level 60  머나먼나라

어떠한 오르막길에도 반드시 내리막길이 있다. -유태격언

댓글 ( 4)

댓글 남기기

작성