IT/안드로이드+JAVA

[안드로이드] 공통적으로 들어가는 배너, 메뉴 등 간단하게 하기

안경 쓴 귀니 2016. 8. 10. 16:50
반응형






[안드로이드] 공통적인 배너, 메뉴 등 간단하게 하기






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();

}

}








반응형