Android : Imageview is not filling to the full width of the screen

on Monday, September 1, 2014


I am having a strange behaviour with the layout for the nexus 5 device only.The problem is after flipping, the image is not setting to the screen size. Here is my code


img.setOnClickListener(new OnClickListener() {



@Override
public void onClick(View arg0) {


flipCard();

}
});



private void flipCard() {
if (mShowingBack) {
getFragmentManager().popBackStack();
return;
}

// Flip to the back.

mShowingBack = true;

// Create and commit a new fragment transaction that adds the fragment
// for the back of
// the card, uses custom animations, and is part of the fragment
// manager's back stack.

getFragmentManager().beginTransaction()

// Replace the default fragment animations with animator resources
// representing
// rotations when switching to the back of the card, as well as animator
// resources representing rotations when flipping back to the front
// (e.g. when
// the system Back button is pressed).
.setCustomAnimations(R.animator.card_flip_right_in,
R.animator.card_flip_right_out,
R.animator.card_flip_left_in,
R.animator.card_flip_left_out)

// Replace any fragments currently in the container view with a
// fragment
// representing the next page (indicated by the just-incremented
// currentPage
// variable).
.replace(R.id.container, new CardBackFragment())

// Add this transaction to the back stack, allowing users to
// press Back
// to get to the front of the card.
.addToBackStack(null)

// Commit the transaction.
.commit();

// Defer an invalidation of the options menu (on modern devices, the
// action bar). This
// can't be done immediately because the transaction may not yet be
// committed. Commits
// are asynchronous in that they are posted to the main thread's message
// loop.
mHandler.post(new Runnable() {
@Override
public void run() {
invalidateOptionsMenu();
}
});
}

@Override
public void onBackStackChanged() {
mShowingBack = (getFragmentManager().getBackStackEntryCount() > 0);

// When the back stack changes, invalidate the options menu (action
// bar).
invalidateOptionsMenu();
}

/**
* A fragment representing the front of the card.
*/
public static class CardFrontFragment extends Fragment {
public CardFrontFragment() {
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

return inflater.inflate(R.layout.singlecard, container, false);
}
}


/**
* A fragment representing the back of the card.
*/
public static class CardBackFragment extends Fragment {
public CardBackFragment() {
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.singlecard_text, container,
false);


} }


My singlecard_text xml


< LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"



android:layout_width="fill_parent"

android:id="@+id/l1"

android:layout_height="match_parent"

android:orientation="vertical" >

<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/inside_card"
android:adjustViewBounds="true"

/>


My singlecard.xml


< RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"



android:layout_width="fill_parent"

android:layout_height="match_parent"

android:orientation="vertical" >


<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"

android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="@drawable/cardread" />


my frame layout.xml


< FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"



android:id="@+id/container"

android:layout_width="match_parent"

android:layout_height="match_parent" >



android:layout_width="match_parent"

android:layout_height="match_parent" >


<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
/>

<ImageView
android:id="@+id/imageView3"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_above="@+id/imageView2"
android:layout_marginBottom="17dp"
android:layout_marginLeft="21dp"
android:layout_toRightOf="@+id/imageView2"
/>

<ImageView
android:id="@+id/imageView4"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/imageView3"
/>

0 comments:

Post a Comment