안녕하세요 초보 개발자 입니다.
지금 하는 프로젝트 소스 간단히 첨부합니다.
(코드 하이라이터 써볼려다가 넘어려워서..카피앤페이스트로... 가독성 안좋아도 한번 훑어봐 주십시요.)
TabLayout.java
(탭 레이아웃을 인플레이트 하고 각탭 리스너(그런데 리스너 여기에 달아도 되는건가요??실행은 되던데..)가 들어있습니다)
public class TabLayout extends LinearLayout {
(중략)
private void init() {
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.tab_main, this, true);
mRl_TabHome = (RelativeLayout) view.findViewById(R.id.rl_tab_home);
mRl_TabBreakdown = (RelativeLayout) view.findViewById(R.id.rl_tab_breakdown);
mRl_TabRegistration = (RelativeLayout) view.findViewById(R.id.rl_tab_registration);
mRl_TabSetting = (RelativeLayout) view.findViewById(R.id.rl_tab_setting);
mRl_TabHome.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Log.v("hgkim", "TabLayout onClick() HomeActivity");
Intent intent = new Intent(mContext, HomeActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
mContext.startActivity(intent);
}
});
(중략)
}
}
tab_layout.xml
(실제 탭의 레이아웃입니다. 탭처럼 보이게 각 탭위젯은 RelateveLayout으로 구성햇습니다.)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="horizontal" >
<RelativeLayout
android:id="@+id/rl_tab_home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#ff0000"
android:orientation="vertical" >
<ImageView
android:id="@+id/iv_tab_home_icon"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:src="@drawable/ic_launcher" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/iv_tab_home_icon"
android:gravity="center"
android:text="@string/tab_home" />
</RelativeLayout>
(중략)
main.xml
(실제 보여질 메인 액티비티 화면입니다. 탭은 최하단에 위치시켰습니다.)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#999999" >
(중략)
<com.test.TabLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
</RelateveLayout>
질문 요약합니다.
1. 인플레이트한 탭레이아웃.java에 탭버튼에 대한 리스너 다는것이 맞는지요??
2. 모든 액티비티의 레이아웃.xml의 하단에 <com.test.TabLayout (중략)> </com.test.TabLayout>이런식으로 추가 해주어야 하나요?? (한 곳에서만 사용해서 모든 액티비티에 적용시킬 방법이 있을련지?)