ImageButton doesn't shows the image - android-imagebutton

I have a problem running with the ImageButton. It does not show the image of the drawable folder, it shows a small gray rectangle.
Demomento I put only the code of the layout of the activity because by clicking on the rectangle that comes out if it does the action.
<?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="mdl.acp.Menu">
<Spinner
android:id="#+id/numeroGru"
android:layout_width="240dp"
android:layout_height="25dp"
android:layout_alignStart="#+id/textView6"
android:layout_below="#+id/textView6"
android:layout_marginLeft="35dp"
android:layout_marginTop="25dp"
tools:layout_editor_absoluteX="82dp"
tools:layout_editor_absoluteY="161dp" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/textView6"
android:layout_below="#+id/numeroGru"
android:layout_marginTop="46dp"
android:text="#string/seleccionaDtAct"
android:textColor="#color/colorPrimary"
android:textSize="18sp"
android:textStyle="bold"
tools:layout_editor_absoluteX="16dp"
tools:layout_editor_absoluteY="251dp" />
<Spinner
android:id="#+id/deporte"
android:layout_width="240dp"
android:layout_height="25dp"
android:layout_alignStart="#+id/textView7"
android:layout_below="#+id/textView7"
android:layout_marginLeft="35dp"
android:layout_marginTop="25dp"
tools:layout_editor_absoluteX="25dp"
tools:layout_editor_absoluteY="338dp"/>
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="#+id/relativeLayout"
android:layout_marginStart="28dp"
android:layout_marginTop="23dp"
android:text="#string/seleccionaAct"
android:textColor="#color/colorPrimary"
android:textSize="18sp"
android:textStyle="bold"
tools:layout_editor_absoluteX="16dp"
tools:layout_editor_absoluteY="84dp" />
<RelativeLayout
android:id="#+id/relativeLayout"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="#color/colorPrimaryDark"
android:layout_alignParentEnd="true">
<TextView
android:id="#+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="#string/nuevoAct"
android:textAlignment="center"
android:textColor="#android:color/white"
android:textSize="30sp"
android:textStyle="bold"
tools:text="#string/nuevoAct" />
</RelativeLayout>
<ImageButton
android:id="#+id/imageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="40dp"
android:elevation="0dp"
app:srcCompat="#drawable/btnsig" />
</RelativeLayout>
The image is a png file whose dimesiones are 80x80 (32 bit color) 5.1k.
I do not know if the problem will have to do with some attribute of the layout of width or height that has as value match parent.
Thanks.

Try this:
Set android:src="#drawable/btnsig" instead of app:srcCompat="#drawable/btnsig".
This will work, just tested.

Related

Xamarin - How can i remove extra space at the top of dialogfragment

I have created a dialog fragment in Xamarin. My only issue is that this fragment shows a grey part on it. And i can't figure out what causes the grey part to appear. Do you guys perhaps know the possible cause ?
I'm using this code to display this dialog :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:focusableInTouchMode="true">
<View
android:id="#+id/makedialogfullscreenChooseSoundTrack"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_gravity="fill_horizontal"
/>
<RelativeLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#e1effa" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Choose Sound Track"
android:textSize="20dp"
android:textColor="#673ab7"
android:padding="15dp"
android:layout_marginRight="25dp"
/>
<ImageView
android:id="#+id/imgCloseSoundDialog"
android:layout_width="33dp"
android:layout_height="33dp"
android:src="#drawable/close_icon"
android:layout_marginBottom="15.5dp"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:layout_centerVertical="true" />
</RelativeLayout>
<LinearLayout
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_width="wrap_content" >
<GridView
android:id="#+id/gvSoundFiles"
android:layout_width="fill_parent"
android:layout_height="400dp"
android:gravity="center"
android:verticalSpacing="5dp"
android:drawSelectorOnTop="true"
android:stretchMode="columnWidth" />
</LinearLayout>
</LinearLayout>
I solved the issue by adding this line in OnCreateView(..) method :
Dialog.Window.RequestFeature(WindowFeatures.NoTitle);
by default the DialogFragment comes with a theme with a title bar, to solve this put the code below in the constructor
SetStyle(DialogFragmentStyle.NoTitle, 0);

Animating layout height produces weird flicker

I'm trying to animate a layout (height) placed under the toolbar and inside an AppbarLayout. I have tried several approaches to this: one of them is using ValueAnimator.ofInt and using this int to set the layout's height. This, however, is kind of choppy. According to some posts I've read, it is because requestLayout() is called in each iteration and that's an expensive operation. Almost every other option I've seen requires requestLayout() to be called. Somewhat old devices will not perform well in that case.
The other approach, which apparently is the most efficient, is to simply declare animateLayoutChanges = true in the parent layout (the AppbarLayout in this case) and simply change the height in code. This does work, but it produces and weird jump, as if the layout instantly and very breifly goes to it's final height, collapses again, and then starts animating normally. The same happens when collapsing.
In the activity, I'm simply calling setVisibility(View.VISIBLE) to expand and newTaskLayout.setVisibility(View.GONE) to collapse. I've also tried setting height to 0 and then making the view GONE to collapse, and setting height to wrap content and then making the view VISIBLE to expand, but the result is the same.
Is there any reason for this and way to avoid it? Or is there a better way to do it?
Heres the XML: (The view being animated is the COnstraintLayout under the toolbar)
<?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="com.adrapps.mytasks.Views.TaskListActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:orientation="vertical"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:title="App"
app:popupTheme="#style/AppTheme.PopupOverlay">
<ProgressBar
android:id="#+id/progressBar"
android:layout_width="30dp"
android:layout_height="30dp"
android:paddingLeft="8dp"
android:paddingStart="8dp"
android:visibility="gone" />
</android.support.v7.widget.Toolbar>
<android.support.constraint.ConstraintLayout
android:id="#+id/new_task_layout"
android:layout_width="match_parent"
android:layout_height="164dp"
android:paddingBottom="16dp"
android:paddingEnd="16dp"
android:paddingStart="16dp"
android:visibility="visible">
<ImageView
android:id="#+id/title_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="0dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="0dp"
android:src="#drawable/ic_label"
app:layout_constraintBottom_toBottomOf="#+id/title_edit_text"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/title_edit_text"
tools:layout_editor_absoluteX="16dp" />
<ImageView
android:id="#+id/date_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="24dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="24dp"
android:layout_marginTop="8dp"
android:src="#drawable/ic_date"
app:layout_constraintBottom_toBottomOf="#+id/date_edit_text"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="#+id/date_edit_text"
app:layout_constraintVertical_bias="0.333" />
<ImageView
android:id="#+id/notification_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="16dp"
android:layout_marginTop="28dp"
android:src="#drawable/ic_notifications_none_black_24dp"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="#+id/date_icon"
app:layout_constraintTop_toBottomOf="#+id/date_icon" />
<EditText
android:id="#+id/title_edit_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:hint="#string/task_title_hint"
android:textAppearance="#style/TextAppearance.AppCompat.Small"
app:layout_constraintLeft_toRightOf="#+id/title_icon"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toEndOf="#id/title_icon"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="#+id/date_edit_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginTop="12dp"
android:hint="#string/task_due_date"
android:textAppearance="#style/TextAppearance.AppCompat.Small"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toRightOf="#+id/date_icon"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toEndOf="#id/date_icon"
app:layout_constraintTop_toBottomOf="#+id/title_edit_text" />
<android.support.v7.widget.AppCompatSpinner
android:id="#+id/notification_spinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginStart="6dp"
android:entries="#array/notification_options"
app:layout_constraintBottom_toBottomOf="#+id/notification_icon"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toRightOf="#+id/notification_icon"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="#+id/notification_icon" />
</android.support.constraint.ConstraintLayout>
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
android:src="#drawable/ic_add_black_24dp" />
<include layout="#layout/content_main" />
</android.support.design.widget.CoordinatorLayout>

Toolbar doesn't hide completely on scroll

I try to hide the toolbar during scroll but then this happens! What do I have to do?
This is the layout code:
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/SimpleTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="#style/SimpleTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_main" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin" />
</android.support.design.widget.CoordinatorLayout>
The view container has following behavior:
app:layout_behavior="#string/appbar_scrolling_view_behavior"
Screenshots:
Before scroll
After scroll
There is something with 'fitsSystemWindows'
Make it false in coordinatorLayout and true in AppBarLayout

Layout is Orientation =vertical when device rotate it wont work

I have the following layout set to Orientation = vertical. But when I rotate the emulator to Landscape, it show the Layout in Landscape.
I want the Layout be in orientation vertical even the device rotate to Landscape.
How to solve this problem? Appreciate your help.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/myLinearLayout"
android:minWidth="25px"
android:minHeight="25px">
<TextView
android:id="#+id/myLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Put Your Name here :" />
<EditText
android:id="#+id/myEditBox"
android:inputType="textMultiLine"
android:textColor="#android:color/background_dark"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="#+id/myButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hey! Click Me" />
</LinearLayout>
android:orientation="vertical" means that the children are inserted into the layout vertically. So when you add more views they will stack underneath each other.
Vertical:
Horizontal:
This is the layout I used. Try change the orientation on your own and see the effect:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<View
android:background="#aabbdd"
android:layout_width="50dp"
android:layout_height="50dp" />
<View
android:background="#341233"
android:layout_width="50dp"
android:layout_height="50dp" />
<View
android:background="#123456"
android:layout_width="50dp"
android:layout_height="50dp" />
<View
android:background="#654321"
android:layout_width="50dp"
android:layout_height="50dp" />
<View
android:background="#550000"
android:layout_width="50dp"
android:layout_height="50dp" />
</LinearLayout>
If you want to lock rotation in your Activity, you need to add the following property to your ActivityAttribute:
ScreenOrientation = ScreenOrientation.Portrait
So it will look something like:
[Activity(Label = "Herp Derp", ScreenOrientation = ScreenOrientation.Portrait)]
public class HerpDerpActivity : Activity
{
// more stuff here
}

Android L activity header image with transparent toolbar and collapse on-scroll

I have a new KitKat App and I'm trying to reproduce in my activity the layout that you can find in the new Play Store App Activity or Google+ Profile Activity.
What I am trying to achieve is to have a transparent toolbar and an "activity-header" image that will collapse on scroll:
Is there any new appcompat widget or a pattern to follow in order to achieve this result?
You can probably find https://github.com/ManuelPeinado/FadingActionBar useful.
Also consult https://plus.google.com/106514622630861903655/posts/Y5iBqpzP4T9 to use the newish Toolbar.
You would want to use CollapsingToolbarLayout.
Android Design Support Library has everything you need.
Just copy the following xml file
<?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"
android:fitsSystemWindows="false"
tools:context="com.example.YourActivity">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="#style/AppTheme.AppBarOverlay">
<!--android:theme="#style/AppTheme.AppBarOverlay"-->
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapse_toolbar"
android:layout_width="match_parent"
android:layout_height="250dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp">
<ImageView
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/my_image"
android:scaleType="centerCrop"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="#style/AppTheme.PopupOverlay"
app:layout_collapseMode="pin"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab_favorite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_anchor="#id/app_bar_layout"
app:layout_anchorGravity="bottom|right|end"
android:src="#drawable/ic_icon2"
android:layout_marginRight="16dp"/>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
android:src="#drawable/ic_icon" />
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="4dp"
android:layout_margin="4dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="8dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bea"
android:textAppearance="?android:attr/textAppearanceSmall"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Abs"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/black87"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
Add translucent style of the status bar
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
</style>
<style name="AppTheme.NoStatusBar" parent="AppTheme.NoActionBar">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
And modify your manifest
<activity
android:name=".YourActivity"
android:label="#string/title"
android:theme="#style/AppTheme.NoStatusBar">
</activity>
There is a example code written by roman nurik ,you can learn from there https://github.com/google/iosched
It helped me. Pay attention on ImageView:
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
>
<ImageView
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/movie_cover"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"
/>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="#style/AppTheme.PopupOverlay"
/>
</android.support.design.widget.CollapsingToolbarLayout>

Resources