I am working in project that contain framelayout display fragments by navigation button next , back and I provide it method below in my code till now every thing works great
here is why I am here , I need make the same function done with navigation button done with swipe button , I add viewpager and pass all fragment to adapter but it give me different view overlapping
Fragment mFragmentsList[] = new Fragment[]{new Slide2Frag() , .... new Slide23Frag()};
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// here is what I need to add viewpager
ViewPager mViewPager = (ViewPager) findViewById(R.id.pager);
adapter = new ViewPageAdapter(getSupportFragmentManager(), mFragmentsList);
mViewPager.setAdapter(adapter);
DisplayFragment(count);
}
// display fragment method
private void DisplayFragment(int display) {
Fragment fragment = null;
switch (display) {
case 2:
fragment = new Slide2Frag();
break;
}
FragmentManager mFragmentManager = getSupportFragmentManager();
FragmentTransaction mTransaction = mFragmentManager.beginTransaction();
mTransaction.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out);
mTransaction.replace(R.id.container, fragment).commit();
}
private void NextMethod() {
if (count < 23) {
count++;
} else {
count = 2;
}
DisplayFragment(count);
}
private void backMethod() {
if (count > 2) {
count--;
} else {
count = 23;
}
DisplayFragment(count);
}
my xml code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background"
android:fitsSystemWindows="true"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/headerlayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="5dp">
<ImageView
android:id="#+id/home_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_gravity="right"
android:layout_marginEnd="219dp"
android:layout_marginRight="219dp"
android:adjustViewBounds="true"
android:background="#drawable/home" />
<ImageView
android:id="#+id/close_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginEnd="60dp"
android:layout_marginRight="60dp"
android:adjustViewBounds="true"
android:background="#drawable/close" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="300dp"
android:layout_height="120dp"
android:layout_marginLeft="25dp"
android:adjustViewBounds="true"
android:background="#drawable/aciloc" />
<ImageView
android:id="#+id/imageView4"
android:layout_width="370dp"
android:layout_height="50dp"
android:layout_below="#+id/home_btn"
android:layout_marginBottom="10dp"
android:layout_toEndOf="#+id/imageView3"
android:layout_toRightOf="#+id/imageView3"
android:adjustViewBounds="true"
android:background="#drawable/leadingppi"
android:scaleType="centerInside" />
</RelativeLayout>
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="400dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_above="#+id/footer_layout"
android:layout_below="#+id/headerlayout" >
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
<LinearLayout
android:id="#+id/footer_layout"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="horizontal"
android:weightSum="6">
<ImageButton
android:id="#+id/left_nav"
android:layout_width="30dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:layout_weight="0.5"
android:adjustViewBounds="true"
android:background="#drawable/left_back"
android:scaleType="centerInside" />
<Button
android:id="#+id/ac20"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginLeft="50dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="#drawable/btn_background"
android:textColor="#color/text_color"
android:text="Aciloc 20mg" />
<Button
android:id="#+id/ac40"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginLeft="50dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="#drawable/btn_background"
android:textColor="#color/text_color"
android:text="Aciloc 40mg" />
<Button
android:id="#+id/profile"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginLeft="50dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="#drawable/btn_background"
android:textColor="#color/text_color"
android:text="PROFILE" />
<Button
android:id="#+id/indications"
android:layout_width="120dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginLeft="50dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="#drawable/btn_background"
android:textColor="#color/text_color"
android:text="INDICATIONS & DOSAGE" />
<Button
android:id="#+id/pack"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginLeft="50dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="#drawable/btn_background"
android:textColor="#color/text_color"
android:text="UNIQUE PACK" />
<ImageButton
android:id="#+id/right_nav"
android:layout_width="30dp"
android:layout_height="match_parent"
android:layout_marginLeft="50dp"
android:layout_weight="0.5"
android:adjustViewBounds="true"
android:background="#drawable/right_back"
android:scaleType="centerInside"
android:textColor="#color/text_color"/>
</LinearLayout>
</RelativeLayout>
here is image explain
Related
Hello Team!!
I'm new on android but i have knoweledge in html and javascript. So i have a JSON that have some options(img,or not img) and i create a recycler view to list this JSON and all ok, later i try that hide some imageView of card because the JSON show that this doesn't have picture. It works fine
But when i do scroll down to bottom limit all imageViews hide, i don't know how solve it and i search in web but i can't find some solution for this issue.
Code in adapter
#RequiresApi(api = Build.VERSION_CODES.O)
#Override
public void onBindViewHolder(postViewHolder postViewHolder, int position) {
addPostTimeline addPost = addPostTimelines.get(position);
try {
CircleImageView img=postViewHolder.imgFoto;
JSONObject fileson=addPost.getDatosTimeine().getJSONObject("file");
// postViewHolder.imgTimeLine = #+id/image_timeline
if(!fileson.getBoolean("err")){ // si tiene archivos adjuntos
switch (fileson.getString("type")){
case "Pic":
imageTimeline imgTm=new imageTimeline(fileson.getString("src"), postViewHolder.imgTimeLine);
imgTm.execute();
break;
default:
postViewHolder.imgTimeLine.setVisibility(View.GONE);
break;
}
}else{
postViewHolder.contentFiles.setVisibility(View.GONE);
}
putImgProfile putImg=new putImgProfile(addPost.getDatosTimeine().getString("pDir"), img);
putImg.execute();
} catch (JSONException e) {
e.printStackTrace();
}
}
Structure of card with recycler
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
android:id="#+id/cvManana"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
card_view:cardCornerRadius="4dp"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto">
<LinearLayout android:background="#drawable/textlines"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:paddingTop="6dp"
android:paddingBottom="6dp"
android:orientation="vertical"
android:id="#+id/post"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/imgPerfil"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center_horizontal"
android:layout_marginRight="8dp"
android:scaleType="centerCrop"
android:src="#mipmap/ic_load_img" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/tv_fechaPost"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="hace 44 minutos sep. 22º 16"
android:textColor="#999" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/tv_nickname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="12dp"
android:text="SonickSeven"
android:textColor="#24650e"
android:textSize="16dp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:id="#+id/contentTextStory">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tv_postTimeLine"
android:textColor="#666"
android:textSize="15dp"
android:layout_gravity="left"
android:text="historias"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/contentFiles">
<!-- image to hide -->
<ImageView
android:id="#+id/image_timeline"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:cropToPadding="false"
android:scaleType="fitStart"
card_view:srcCompat="#drawable/campo_manana" />
<!-- end imagen to hide -->
</LinearLayout>
<LinearLayout
android:paddingTop="4dp"
android:paddingBottom="7dp"
android:layout_gravity="left"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:gravity="right"
android:layout_weight="1.0"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageButton
android:id="#+id/bt_reply"
android:layout_gravity="center_vertical"
android:scaleType="centerCrop"
android:layout_width="20dp"
android:layout_height="20dp"
android:background="#mipmap/ic_reply_gray"/>
<TextView
android:id="#+id/countReply"
android:text="(3)"
android:textSize="12dp"
android:layout_gravity="center"
android:textColor="#999"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_weight="1.0"
android:layout_width="match_parent"
android:gravity="right"
android:layout_height="wrap_content">
<ImageButton
android:id="#+id/bt_share"
android:scaleType="centerCrop"
android:layout_gravity="center_vertical"
android:layout_width="20dp"
android:layout_height="20dp"
android:background="#mipmap/ic_share_gray"/>
<TextView
android:id="#+id/countShare"
android:text="(3)"
android:textSize="12dp"
android:layout_gravity="center"
android:textColor="#999"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_weight="1.0"
android:layout_width="match_parent"
android:gravity="right"
android:layout_height="wrap_content">
<ImageButton
android:layout_gravity="center_vertical"
android:id="#+id/bt_like"
android:scaleType="centerCrop"
android:layout_width="20dp"
android:layout_height="20dp"
android:background="#mipmap/ic_like_gray"/>
<TextView
android:id="#+id/countLike"
android:text="(3)"
android:textSize="12dp"
android:layout_gravity="center"
android:textColor="#999"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_weight="1.0"
android:layout_width="match_parent"
android:gravity="right"
android:layout_height="wrap_content">
<ImageButton
android:id="#+id/bt_dislike"
android:layout_gravity="center_vertical"
android:scaleType="centerCrop"
android:layout_width="20dp"
android:layout_height="20dp"
android:background="#mipmap/ic_nolike_gray"/>
<TextView
android:id="#+id/countNoLike"
android:text="(3)"
android:textSize="12dp"
android:layout_gravity="center"
android:textColor="#999"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
i saw that when i go to bottom of scroll and up the switch trigger again, but it doesn't could because the recycler view run all array JSON. Sorry i can understand how work android-java
Try this in onBindViewHolder method:
#RequiresApi(api = Build.VERSION_CODES.O)
#Override
public void onBindViewHolder(postViewHolder postViewHolder, int position) {
addPostTimeline addPost = addPostTimelines.get(position);
try {
CircleImageView img=postViewHolder.imgFoto;
JSONObject fileson=addPost.getDatosTimeine().getJSONObject("file");
if(!fileson.getBoolean("err") && fileson.getString("type").equals("pic")){
//image must be visible and no error
postViewHolder.imgTimeLine.setVisibility(View.VISIBLE);
postViewHolder.contentFiles.setVisibility(View.VISIBLE);
imageTimeline imgTm=new imageTimeline(fileson.getString("src"), postViewHolder.imgTimeLine);
imgTm.execute();
}else if(!fileson.getBoolean("err") && !fileson.getString("type").equals("pic")){
//image shouldn't be visible and no error
postViewHolder.imgTimeLine.setVisibility(View.GONE);
postViewHolder.contentFiles.setVisibility(View.VISIBLE);
}else{
//error
postViewHolder.imgTimeLine.setVisibility(View.GONE);
postViewHolder.contentFiles.setVisibility(View.GONE);
}
putImgProfile putImg=new putImgProfile(addPost.getDatosTimeine().getString("pDir"), img);
putImg.execute();
} catch (JSONException e) {
e.printStackTrace();
}
}
You need to reset the visible where you don’t need to set the visible.
postViewHolder.imgTimeLine.setVisibility(View.VISIBLE);// reset
if(!fileson.getBoolean("err")){ // si tiene archivos adjuntos
switch (fileson.getString("type")){
case "Pic":
imageTimeline imgTm=new imageTimeline(fileson.getString("src"),
postViewHolder.imgTimeLine);
imgTm.execute();
break;
default:
postViewHolder.imgTimeLine.setVisibility(View.GONE);
break;
}
}else{
postViewHolder.contentFiles.setVisibility(View.GONE);
}
I was trying to make an intent from activity to a specific fragment from a navigation drawer. i was try the fragment transaction but it is not working on me.
This is my code:
My Activity (On-click activity going to a specific Fragment from a navigation drawer):
private void checkCarts() {
checkCart.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
fragment=new EppViewCartV2();
if (fragment != null) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.frams, fragment);
ft.commit();
}
}
});
}
Error code upon logcat
[1]: https://i.stack.imgur.com/uuFMq.png
my error (upon using getFragmentManager)
my farams (framelayout):
this is my basic activity ():
-this is the appbar activity:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ItemViewProducts.EppItemPreviewPhone">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#f2f2f2"
app:elevation="0dp"
android:theme="#style/AppTheme.NoActionBar.AppBarOverlay">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/view_back"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginLeft="18dp"
android:layout_marginTop="20dp"
android:src="#drawable/arrow_back"/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="15dp"
android:layout_height="wrap_content">
<RelativeLayout
android:id="#+id/qqt"
android:layout_width="wrap_content"
android:layout_marginTop="20dp"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/view_cart2"
android:layout_width="26dp"
android:layout_marginRight="10dp"
android:layout_height="26dp"
android:src="#drawable/shopping"/>
</RelativeLayout>
<TextView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginTop="12dp"
android:id="#+id/badge_notification"
android:layout_alignRight="#id/qqt"
android:background="#drawable/item_status"
android:textAlignment="center"
android:text="12"
android:textColor="#fff"
android:padding="3dp"
android:textSize="10sp"
android:textStyle="bold"
></TextView>
</RelativeLayout>
</RelativeLayout>
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_epp_item_preview_phone" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fbutton_add_to_cart"
app:rippleColor="#null"
app:backgroundTint="#null"
app:maxImageSize="30dp"
android:scaleType="center"
android:layout_margin="#dimen/fab_margin"
android:backgroundTint="#b578ff"
app:srcCompat="#drawable/cart_big"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end" />
</android.support.design.widget.CoordinatorLayout>
the content Activity:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#f2f2f2"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".ItemViewProducts.EppItemPreviewPhone"
tools:showIn="#layout/activity_epp_item_preview_phone">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/relativeLayout2"
android:layout_width="match_parent"
android:layout_height="410dp"
android:layout_marginBottom="8dp"
android:background="#drawable/radius_all"
app:layout_constraintBottom_toTopOf="#+id/relativeLayout4"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="240dp">
<android.support.v4.view.ViewPager
android:id="#+id/viewPager2"
android:layout_width="match_parent"
android:background="#drawable/radius_all"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:layout_height="240dp"
android:layout_marginBottom="5dp" />
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="#+id/rightright"
android:layout_centerVertical="true"
android:src="#drawable/leftleft"
android:layout_marginLeft="10dp">
</ImageView>
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_centerVertical="true"
android:id="#+id/leftleft"
android:layout_alignParentRight="true"
android:src="#drawable/rightright"
android:layout_marginRight="10dp">
</ImageView>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_marginTop="70dp"
android:layout_height="match_parent">
<TextView
android:layout_width="280dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="190dp"
android:text="Harman Karton - AURA STUDIO 2"
android:textColor="#000"
android:id="#+id/view_subject"
android:textSize="18dp"
android:textStyle="bold" />
<TextView
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginTop="245dp"
android:id="#+id/view_on_hand"
android:text="Available(150)"
android:textSize="11dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="238dp"
android:text="P 14,999.00"
android:id="#+id/view_new_price"
android:textColor="#f24800"
android:textSize="21dp"
android:textStyle="bold" />
<TextView
android:layout_width="110dp"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="270dp"
android:text="P 145,999.00"
android:id="#+id/view_srp"
android:textSize="16dp" />
<TextView
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginLeft="150dp"
android:layout_marginTop="270dp"
android:text=" - 50%"
android:id="#+id/view_discount"
android:textColor="#af0000"
android:textSize="17dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="275dp"
android:layout_marginRight="110dp"
android:layout_alignParentRight="true"
android:text="x"
android:textSize="12dp" />
<ImageView
android:layout_width="20dp"
android:id="#+id/view_btn_less"
android:layout_height="20dp"
android:layout_marginTop="273dp"
android:layout_marginRight="85dp"
android:layout_alignParentRight="true"
android:src="#drawable/left_arrow" />
<TextView
android:layout_width="30dp"
android:layout_height="20dp"
android:layout_marginTop="273dp"
android:layout_marginRight="53dp"
android:layout_alignParentRight="true"
android:text="1"
android:textAlignment="center"
android:id="#+id/view_count"
android:textColor="#000"
android:textSize="14dp" />
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:id="#+id/view_btn_add"
android:layout_marginTop="273dp"
android:layout_marginRight="30dp"
android:layout_alignParentRight="true"
android:src="#drawable/right_arrow"
android:textSize="17dp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="300dp"
android:layout_marginRight="20dp"
android:background="#bababa"
android:src="#drawable/right_arrow"
android:textSize="17dp" />
<TextView
android:layout_width="45dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="30dp"
android:layout_marginTop="310dp"
android:layout_marginRight="150dp"
android:text="Total"
android:textSize="15dp" />
<TextView
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="30dp"
android:layout_marginTop="305dp"
android:layout_marginRight="10dp"
android:text="P 14,999.00"
android:id="#+id/view_total"
android:textColor="#000"
android:textSize="18dp"
android:textStyle="bold" />
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativeLayout4"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="420dp"
android:layout_marginBottom="8dp"
android:background="#drawable/radius_all"
app:layout_constraintBottom_toTopOf="#+id/relativeLayout3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/relativeLayout2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="25dp"
android:text="Color Variation"
android:textSize="12dp" />
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:layout_centerVertical="true"
android:layout_marginRight="190dp"
android:id="#+id/color5"
android:layout_alignParentRight="true"
android:textSize="17dp" />
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:layout_centerVertical="true"
android:layout_marginRight="150dp"
android:id="#+id/color4"
android:layout_alignParentRight="true"
android:textSize="17dp" />
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:id="#+id/color3"
android:layout_centerVertical="true"
android:layout_marginRight="110dp"
android:layout_alignParentRight="true"
android:textSize="17dp" />
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:layout_marginRight="70dp"
android:id="#+id/color2"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:textSize="17dp" />
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:layout_marginRight="30dp"
android:layout_centerVertical="true"
android:id="#+id/color1"
android:layout_alignParentRight="true"
android:textSize="17dp" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_marginTop="478dp"
android:orientation="vertical"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:text="Product description"
android:textSize="14dp"/>
<TextView
android:layout_width="match_parent"
android:layout_marginTop="3dp"
android:layout_height="wrap_content"
android:background="#drawable/radius_all"
android:textColor="#000"
android:id="#+id/view_product_description"
android:text=" \n \n
- Enter your model number \n \n
- Compatible with all devices with a stereo minijack output \n \n
- Outstanding bass performance \n \n
- Touch volume and mute controls \n \n
- Subwoofer volume control \n \n"
android:textSize="11dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="8dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:text="Product specification"
android:textSize="14dp"/>
<TextView
android:layout_width="match_parent"
android:layout_marginTop="3dp"
android:layout_height="wrap_content"
android:background="#drawable/radius_all"
android:textColor="#000"
android:id="#+id/view_product_specification"
android:text=" \n \n
- Enter your model number \n \n
- Compatible with all devices with a stereo minijack output \n \n
- Outstanding bass performance \n \n
- Touch volume and mute controls \n \n
- Subwoofer volume control \n \n"
android:textSize="11dp" />
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:gravity="center"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:layout_marginRight="20dp"
android:text="Other Products"
android:textSize="15dp"
android:textStyle="bold"
android:layout_centerHorizontal="true"/>
<android.support.v7.widget.RecyclerView
android:layout_width="wrap_content"
android:id="#+id/view_product_other_items"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_marginTop="3dp"
android:layout_centerHorizontal="true">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</ScrollView>
When you are using android.support.v4.app.FragmentManager then you should use getSupportFragmentManager() and if you are using android.app.FragmentManager then use getFragmentManager().
private void checkCarts() {
checkCart.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
fragment=new EppViewCartV2();
if (fragment != null) {
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.frams, fragment);
ft.commit();
}
}
});
}
When you say ft.replace(R.id.frams, fragment);, you are saying "put fragment into the container specified by R.id.frams.
That means that a layout with the id R.id.frams must be in your layout, in this case - in your activity's layout (since you're calling getSupportFragmentManager() and getting the activity's FragmentManager).
You need to change your activity's layout to include that layout.
I was figure it out my answer..
instead of using the fragment transaction , i use intent
first, i was intent my activity to my navigation drawer and add a static String data (catch data)
my Activity:
private void checkCarts() {
checkCart.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(getApplicationContext(),EppDrawer.class);
openSisame="okay";
startActivity(i);
}
});
}
and in my drawer, ive set a try catch hat if it is okay, it will go to a fragment that ive like to display, and if it is not i will display my main page.
like this one:
try{
if(EppItemPreviewPhone.openSisame.equals("okay")){
displaySelectedScreen(2131296453);
}
}catch (Exception e){
Toast.makeText(this, "NONE", Toast.LENGTH_SHORT).show();
fragment=new EppMainFragment();
if (fragment != null) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.frams, fragment);
ft.commit();
}
}
private void displaySelectedScreen(int itemId) {
//initializing the fragment object which is selected
switch (itemId) {
case R.id.nav_home:
fragment = new EppMainFragment();
break;
case R.id.nav_my_account:
fragment = new EppMyAccount();
break;
case R.id.nav_view_cart:
fragment = new EppViewCartV2();
break;
case R.id.nav_order:
fragment = new EppOrderHistory();
break;
case R.id.nav_find:
fragment = new EppFindProduct();
break;
case R.id.nav_about:
fragment = new AboutFragment();
break;
}
//replacing the fragment
if (fragment != null) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.frams, fragment);
ft.commit();
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
}
hence: this value (2131296453) is a value from the id of my fragment.
thank you guys for your answers even it is solve my code but you give me a logic to solve it :)
I have a fragment class with 6 hard-coded cardviews. I want the user to be able to click on them and it open up another activity. Each opens to different activity. Currently, when the user clicks on the cardview it opens the new activity, but doesn't show the layout. For example, when the user clicks on the science cardview it just shows a blank page, but doesn't show the layout with the button.
Here is my fragment page code:
public class show_class extends Fragment implements
View.OnClickListener {
private CardView science_cv, math_cv, social_studies_cv, english_cv,
tech_cv, other_cv;
private DatabaseReference myRef ;
//List<show_class> list;
// private RecyclerView recycle;
// Button view;
public show_class() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.activity_show_class, container, false);
//find cardview's by ids
science_cv = (CardView) view.findViewById(R.id.science);
math_cv = (CardView) view.findViewById(R.id.math);
social_studies_cv = (CardView) view.findViewById(R.id.social_studies);
english_cv = (CardView) view.findViewById(R.id.English);
tech_cv = (CardView) view.findViewById(R.id.tech);
other_cv= (CardView) view.findViewById(R.id.other);
//set onclicklistener to cardviews
science_cv.setOnClickListener(this);
social_studies_cv.setOnClickListener(this);
math_cv.setOnClickListener(this);
english_cv.setOnClickListener(this);
tech_cv.setOnClickListener(this);
other_cv.setOnClickListener(this);
return view;
}
public void onClick (View v){
Intent i;
switch (v.getId()) {
case R.id.science:
i = new Intent(getContext(), Science_classes.class);
case R.id.math: i = new Intent(getContext(), Math_classes.class);startActivity(i);break;
case R.id.social_studies: i = new Intent(getContext(), Social_studies_classes.class);startActivity(i);break;
case R.id.English: i = new Intent(getContext(), English_classes.class);startActivity(i);break;
case R.id.tech: i = new Intent(getContext(), Technology_classes.class);startActivity(i);break;
case R.id.other: i = new Intent(getContext(), Other_classes.class);startActivity(i);break;
default:break;
}
}
}
Here is my xml for the fragment page:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_height="match_parent">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#a4a4a4">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:clipToPadding="false"
android:gravity="center"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:clickable="true"
android:focusable="true"
android:foreground="?android:selectableItemBackground"
android:id="#+id/science"
android:layout_width="160dp"
android:layout_height="190dp"
android:layout_margin="10dp"
android:padding="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="130dp"
android:gravity="center"
android:background="#color/colorSecondary">
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:src="#drawable/ic_launcher_background"
android:padding="10dp"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Science"
android:textColor="#000"
android:textSize="18dp" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/lightgray"
android:layout_margin="2dp"/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:onClick="show2"
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"
android:id="#+id/math"
android:layout_width="160dp"
android:layout_height="190dp"
android:layout_margin="10dp"
android:padding="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="130dp"
android:gravity="center"
android:background="#color/colorSecondary">
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:padding="10dp"
android:src="#drawable/ic_launcher_background" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Math"
android:textColor="#000"
android:textSize="18dp" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/lightgray"
android:layout_margin="2dp"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
<LinearLayout
android:clipToPadding="false"
android:gravity="center"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:onClick="show3"
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"
android:id="#+id/English"
android:layout_width="160dp"
android:layout_height="190dp"
android:layout_margin="10dp"
android:padding="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="130dp"
android:gravity="center"
android:background="#color/colorSecondary">
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:padding="10dp"
android:src="#drawable/ic_launcher_background" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="English"
android:textColor="#000"
android:textSize="18dp" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/lightgray"
android:layout_margin="2dp"/>
/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:onClick="show4"
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"
android:id="#+id/social_studies"
android:layout_width="160dp"
android:layout_height="190dp"
android:layout_margin="10dp"
android:padding="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="130dp"
android:gravity="center"
android:background="#color/colorSecondary">
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:padding="10dp"
android:src="#drawable/ic_launcher_background" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Social Studies"
android:textColor="#000"
android:textSize="18dp" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/lightgray"
android:layout_margin="2dp"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
<LinearLayout
android:clipToPadding="false"
android:gravity="center"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:onClick="show5"
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"
android:id="#+id/tech"
android:layout_width="160dp"
android:layout_height="190dp"
android:layout_margin="10dp"
android:padding="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:background="#color/colorSecondary"
android:layout_width="match_parent"
android:layout_height="130dp"
android:gravity="center"
>
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:src="#drawable/ic_launcher_background"
android:padding="10dp"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Technology"
android:textColor="#000"
android:textSize="18dp" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/lightgray"
android:layout_margin="2dp"/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:onClick="show6"
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"
android:id="#+id/other"
android:layout_width="160dp"
android:layout_height="190dp"
android:layout_margin="10dp"
android:padding="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="130dp"
android:gravity="center"
android:background="#color/colorSecondary">
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:padding="10dp"
android:src="#drawable/ic_launcher_background" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Other"
android:textColor="#000"
android:textSize="18dp" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/lightgray"
android:layout_margin="2dp"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</LinearLayout>
</ScrollView></FrameLayout>
Here is the code for the science class i am trying to go to(it is the same for all):
public class Science_classes extends AppCompatActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_science_classes);
}
}
Here is the xml, just a simple button:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Science_classes">
<Button
android:id="#+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
there is a missing startActivity(i); and break; statement in the first case case R.id.science: that is the reason that after clicking science you are ending up with maths case and starting a maths activity. Will have to check if that is the problem of the blank screen. Is you maths activity layout empty?
'in your show_class fragment in onClick() you are not starting the Science_classes activity like.'
'in first case of R.id.science'
startActivity(i);
I have 2 fragments, and want to do a shared element transition between them.
The item in an recyclerview, with an adapter, contains a textview that should be animated to an edittext in the next fragment.
The recyclerview is in an fragment too.
Here's my code:
item layout for viewholder from adapter:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/row_container"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:background="#FAFAFA"
android:elevation="0dp"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:attr/selectableItemBackground"
android:elevation="0dp"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:elevation="0dp"
>
<RelativeLayout
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#null"
android:elevation="0dp"
android:layout_centerVertical="true"
>
<ImageButton
android:id="#+id/notify_btn"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/ic_bookmark_black_24dp"
android:background="#null"
android:tint="#9E9E9E"
android:layout_centerInParent="true"
/>
</RelativeLayout>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginRight="20dp"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="#android:color/black"
android:layout_alignParentTop="true"
android:maxLines="1"
android:ellipsize="end"
android:transitionName="title"
/>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/text"
android:layout_below="#id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginRight="20dp"
android:textSize="15sp"
android:maxLines="2"
android:layout_alignParentBottom="true"
android:textColor="#android:color/black"
android:ellipsize="end"
android:transitionName="text"
/>
</RelativeLayout>
<ImageView
android:id="#+id/fav"
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_margin="5dp"
android:visibility="invisible"
android:src="#drawable/ic_star_black_24dp"
/>
</RelativeLayout>
MyAdapter class, the item row click:
row.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Fragment frag = new Fragment_Notice();
int tin_title = Integer.parseInt(String.valueOf(title.getText().length()));
if ( (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) &&
( SharedPrefHelper.getBool("shared_transition") == true) &&
( tin_title >= 1 ) ) {
//Exit transition for old fragment
frag.setSharedElementReturnTransition(TransitionInflater.from(context).inflateTransition(R.transition.title_transform));
frag.setExitTransition(TransitionInflater.from(context).inflateTransition(android.R.transition.explode));
//Enter transition for new fragment
frag.setSharedElementEnterTransition(TransitionInflater.from(context).inflateTransition(R.transition.title_transform));
frag.setEnterTransition(TransitionInflater.from(context).inflateTransition(android.R.transition.explode));
ft.replace(R.id.container, frag, "NoticeTag")
.addToBackStack(null)
.addSharedElement(title, "title")
.commit();
} else {
int open = R.anim.abc_fade_in;
int close = R.anim.abc_fade_out;
ft.setCustomAnimations(open, close, open, close)
.replace(R.id.container, frag, "NoticeTag")
.addToBackStack(null)
.commit();
}
}
});
Layout from final fragment:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="invisible"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="15dp"
android:layout_marginRight="10dp"
android:padding="10dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<EditText
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:nextFocusForward="#id/text"
android:imeOptions="actionNext"
android:singleLine="true"
android:ems="16"
android:hint="#string/title"
android:textColor="#212121"
android:textColorHint="#757575"
android:background="#null"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:scrollbars="horizontal"
android:transitionName="title"
/>
<EditText
android:id="#+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/text"
android:textColor="#212121"
android:textColorHint="#757575"
android:background="#null"
android:layout_marginLeft="2dp"
android:transitionName="text"
/>
<View
android:id="#+id/line"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp"
android:elevation="0dp"
android:background="#color/grey"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
>
<ImageButton
android:id="#+id/fav"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_star_black_24dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:padding="5dp"
android:background="?android:attr/selectableItemBackground"
android:tint="#9E9E9E"
/>
</RelativeLayout>
</LinearLayout>
</ScrollView>
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:gravity="top"
android:id="#+id/snackbar">
</android.support.design.widget.CoordinatorLayout>
The textview doesnt animate to an edittext.
The explode animation appears.
Between activities the animation works.
Any suggestions how to fix?
I have a map activity, which also contains a navigation drawer layout with items in the drawer. I want to be able to click an item in the drawer, and the item i choose opens an activity. I tried using startActivity to call the class in a separate page, but it distorted my xml file in my emulator. I also tried updateFragment(); but it showed my new class as an error. would anyone know what i can do?
this is my MapActivity.java file
public class MapsActivity extends FragmentActivity {
private GoogleMap mMap;
DrawerLayout drawerLayout;
ListView listView;
ActionBarDrawerToggle drawerToggle;
String[]items;
int selectedPosition=0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
setUpMapIfNeeded();
items=getResources().getStringArray(R.array.options);
drawerLayout=(DrawerLayout)findViewById(R.id.drawer_layout);
listView=(ListView)findViewById(R.id.drawer_list);
ArrayAdapter<String>adapter=new ArrayAdapter<String>(MapsActivity.this,R.layout.drawer_list_item,items);
listView.setAdapter(adapter);
drawerToggle=new ActionBarDrawerToggle(MapsActivity.this,drawerLayout,R.drawable.images,R.string.drawer_open,R.string.drawer_close){
#Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
}
#Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
}
};
drawerLayout.setDrawerListener(drawerToggle);
// getActionBar().setHomeButtonEnabled(false);
// getActionBar().setDisplayHomeAsUpEnabled(false);
// getActionBar().setDisplayShowTitleEnabled(false);
// getActionBar().setDisplayShowHomeEnabled(false);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
selectedPosition = position;
if (selectedPosition==2){
startActivity(new Intent(MapsActivity.this, MenuActivity.class);
}
// updateFragment();
drawerLayout.closeDrawer(listView);
}
});
// selectedPosition=0;
// updateFragment();
}
#Override
protected void onResume() {
super.onResume();
setUpMapIfNeeded();
}
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.
if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
// Check if we were successful in obtaining the map.
if (mMap != null) {
setUpMap();
}
}
}
private void setUpMap() {
mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
}
private void updateFragment() {
FragmentManager fragmentManager=getFragmentManager();
WebViewFragment rFragment=new WebViewFragment();
Bundle data=new Bundle();
data.putString("title",items[selectedPosition]);
rFragment.setArguments(data);
FragmentTransaction ft=fragmentManager.beginTransaction();
ft.replace(R.id.content_frame,rFragment);
ft.commit();
}
#Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
drawerToggle.syncState();
}
}
My MenuActivity.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.xxxxxx.qdoba.MenuFragment">
<!-- TODO: Update blank fragment layout -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="#drawable/woodcrop">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="MENU"
android:id="#+id/textView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textStyle="bold"
android:textSize="60dp"
android:textColor="#ff912424" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="140dp"
android:layout_marginTop="100dp">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp" />
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView2"
android:layout_marginTop="20dp"
android:layout_marginLeft="30dp" />
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView3"
android:layout_marginTop="20dp"
android:layout_marginLeft="30dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="140dp"
android:layout_gravity="center_horizontal">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView4"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp" />
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView5"
android:layout_marginTop="20dp"
android:layout_marginLeft="30dp" />
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView6"
android:layout_marginTop="20dp"
android:layout_marginLeft="30dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="140dp"
android:layout_gravity="center_horizontal">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView7"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp" />
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView8"
android:layout_marginTop="20dp"
android:layout_marginLeft="30dp" />
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView9"
android:layout_marginTop="20dp"
android:layout_marginLeft="30dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="140dp"
android:layout_gravity="center_horizontal">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView10"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp" />
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView11"
android:layout_marginTop="20dp"
android:layout_marginLeft="30dp" />
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView12"
android:layout_marginTop="20dp"
android:layout_marginLeft="30dp" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
this is how it looks in the preview;
this is how it looks on the emulator :(
one image:
It happens because you are using layout_width="100dp" for every image view and 20dp of margin, so the final width of your layout bigger than screen width of device. You can see it if you change preview from Nexus 6 to Nexus One, for example.
You can use layout_weight parameter for every image or TableLayout with 3 columns, or you may try to use GridLayout.
Try this, for example.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imageView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:minHeight="50dp"
/>
<ImageView
android:id="#+id/imageView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:minHeight="50dp"
/>
<ImageView
android:id="#+id/imageView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:minHeight="50dp"
/>
</LinearLayout>
Or with same effect
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/textView"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:stretchColumns="*">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/imageView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:minHeight="50dp"
/>
<ImageView
android:id="#+id/imageView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:minHeight="50dp"
/>
<ImageView
android:id="#+id/imageView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:minHeight="50dp"
/>
</TableRow>
//your other rows
</TableLayout>