[안드로이드] 공통적인 배너, 메뉴 등 간단하게 하기
framlayout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/banner_img"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/img"/>
</LinearLayout>
main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/banner_frag"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</FrameLayout>
</RelativeLayout>
Framlayout.java
public class Framlayout extends Fragment {
ImageView banner_img;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.framlayout, container, false);
banner_img = (ImageView) view.findViewById(R.id.banner_img);
banner_img.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.e("Log", "onClick");}
});
return view;
}
MainActivity.java
public class MainActivity extends AppCompatActivity {
Fragment fragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
fragment = new Banner();
FragmentManager fm = getFragmentManager();
FragmentTransaction fragmentTransaction = fm.beginTransaction();
fragmentTransaction.replace(R.id.banner_frag, fragment);
fragmentTransaction.commit();
}
}
'IT > 안드로이드+JAVA' 카테고리의 다른 글
[안드로이드] 프래그먼트, intent 등에서 Context 사용하기 (getContext() 안먹힐때) (1) | 2016.08.12 |
---|---|
[안드로이드] ScrollView 사용법, 주의할 점 / 스크롤뷰 사용법, 주의한 점 (1) | 2016.08.11 |
[안드로이드] split 사용법, split 공백, 공백 섞인 String 자르기 (0) | 2016.08.09 |
[안드로이드] 프래그먼트 새로고침, 갱신, 리로드 (0) | 2016.08.09 |
[안드로이드스튜디오] 슬라이드 메뉴 예제 (slide menu) (0) | 2016.08.08 |