Here is my fooddetail activity codes
public class FoodDetail extends AppCompatActivity {
TextView food_name,food_price,food_description;
ImageView food_image;
CollapsingToolbarLayout collapsingToolbarLayout;
FloatingActionButton btnCart;
ElegantNumberButton numberButton;
String foodId="";
FirebaseDatabase database;
DatabaseReference food;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_food_detail);
database = FirebaseDatabase.getInstance();
food = database.getReference("Food");
numberButton = (ElegantNumberButton)findViewById(R.id.number_button);
btnCart = (FloatingActionButton)findViewById(R.id.btnCart);
food_name = (TextView)findViewById(R.id.food_name);
food_description = (TextView)findViewById(R.id.food_description);
food_price = (TextView)findViewById(R.id.food_price);
food_image = (ImageView) findViewById(R.id.img_food);
collapsingToolbarLayout = (CollapsingToolbarLayout)findViewById(R.id.collapsing);
collapsingToolbarLayout.setExpandedTitleTextAppearance(R.style.ExpandedAppBar);
collapsingToolbarLayout.setCollapsedTitleTextAppearance(R.style.CollapsedAppBar);
if (getIntent() != null)
foodId = getIntent().getStringExtra("FoodId");
if(!foodId.isEmpty())
{
getDetailFood(foodId);
}
}
private void getDetailFood(String foodId)
{
food.child(foodId).addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
Food food = dataSnapshot.getValue(Food.class);
Picasso.with(getBaseContext()).load(food.getImage()).into(food_image);
collapsingToolbarLayout.setTitle(food.getName());
food_price.setText(food.getPrice());
food_name.setText(food.getName());
food_description.setText(food.getDescription());
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}
and here is my xml
<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.order.m.jersonsordering.FoodDetail">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/Base.ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true"
android:id="#+id/app_bar_layout">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:id="#+id/collapsing"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:contentScrim="#0e0d0e">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="#null"
app:layout_collapseMode="parallax"
android:id="#+id/img_food"
android:scaleType="centerCrop" />
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="parallax"
android:id="#+id/toolbar"
app:title="Food Name">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/btnCart"
android:src="#drawable/ic_shopping_cart_black_24dp"
android:backgroundTint="#android:color/white"
android:elevation="6dp"
app:pressedTranslationZ="12dp"
app:layout_anchor="#id/app_bar_layout"
app:layout_anchorGravity="bottom|right|end"
app:useCompatPadding="true"/>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:id="#+id/nestedScrollView">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardElevation="5dp"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/food_name"
android:layout_marginTop="8dp"
android:padding="12dp"
android:textColor="#000000"
android:text="Food Name"
android:textSize="21sp"
android:textStyle="bold"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/layout_price"
android:orientation="horizontal">
<TextView
android:layout_width="1dp"
android:layout_weight="9"
android:layout_height="wrap_content"
android:id="#+id/food_price"
android:layout_marginTop="8dp"
android:padding="12dp"
android:textColor="#000000"
android:text="1,000PHP"
android:textStyle="bold"
android:textSize="15sp"/>
</LinearLayout>
<com.cepheuen.elegantnumberbutton.view.ElegantNumberButton
android:layout_width="100dp"
android:layout_height="30dp"
android:id="#+id/number_button"
android:layout_marginTop="8dp"
android:layout_marginLeft="8dp"
android:layout_marginBottom="18dp"
app:textSize="8sp"
app:backGroundColor="#color/colorAccent"
app:textColor="#000000"
app:initialNumber="1"
app:finalNumber="20">
</com.cepheuen.elegantnumberbutton.view.ElegantNumberButton>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
app:cardElevation="5dp"
app:cardUseCompatPadding="true"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/food_description"
android:layout_marginTop="12dp"
android:lineSpacingMultiplier="1.5"
android:padding="12dp"
android:text="Description"
android:textColor="#000000"
android:textSize="14sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</android.support.v7.widget.CardView>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
I dont know what is causing the error and i cant resolve it I tried to rebuild and clean the project
I also tried searching for similar error but none is showing
the app keeps on closing and then thats the error(attached photo)
pls help me thank you :)
First make sure that you have included design library implementation 'com.android.support:design:26.+' in your application level build.gradle.
Then replace:
<android.support.design.widget.FloatingActionButton
...
...
android:backgroundTint
/>
with
<android.support.design.widget.FloatingActionButton
...
...
app:backgroundTint
/>
**Main Layout**:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="#+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/White">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="#color/white"
app:titleEnabled="false"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<TextView
android:id="#+id/collapsing_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:adjustViewBounds="true"
android:text="Journal Name, Volume No, Issue"
android:textSize="40sp"
android:textStyle="bold"
android:textColor="#color/black"
android:padding="30dp"
android:layout_marginTop="?attr/actionBarSize"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/primary"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<include layout="#layout/article_listing_content"/>
</android.support.design.widget.CoordinatorLayout>
**Layout**:article_listing_content
<?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"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<RelativeLayout
android:id="#+id/rv_container"
android:visibility="visible"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:longClickable="true"
android:elevation="50dp"
android:scrollbars="vertical"/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/error_msg_container"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/error_msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
</RelativeLayout>
I want to disable the collapsing of the title field (collapsing_title - TextView inside CollapsingToolbarLayout) if there is not enough data in the recycler view. ie Collapsing should only happen if there is more data / scrolling is required, else collapsing should be disabled.
You can "disable" this collapsing behavior by modifying your CollapsingToolbarLayout's app:layout_scrollFlags attribute.
As a layout_ attribute, this is part of the parent's LayoutParams (i.e. AppBarLayout.LayoutParams). As expected, this class exposes the method setScrollFlags().
To disable collapsing:
CollapsingToolbarLayout collapsing =
(CollapsingToolbarLayout) findViewById(R.id.toolbar_layout);
AppBarLayout.LayoutParams params =
(AppBarLayout.LayoutParams) collapsing.getLayoutParams();
params.setScrollFlags(0);
collapsing.setLayoutParams(params);
To re-enable collapsing, simply replace the setScrollFlags() call with one that passes in your original flags:
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED);
I want to develop collapsingToolbar with TabLayout. So I was tried with ViewPager with NesteScroolView and CollpasingToolbar, TabLayout Not showing the fragments.
If I remove the "NestedScrollView", then it is working, but if you scroll the fragment page, toolbar collapsing not working. Only CollapsingToolbar components (ImageView and TabLayout) only expanding and collapsing not ViewPager Items.
any Idea please help me.
<?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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="250dp"
android:id="#+id/appbar"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/collapsing_toolbar"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ViewFlipper
android:id="#+id/view_flipper"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax"
>
</ViewFlipper>
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:id="#+id/toolbar"
android:layout_gravity="top"
android:background="#color/colorPrimaryDark"
app:layout_collapseMode="pin">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Temples"
/>
</RelativeLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways">
<android.support.design.widget.TabLayout
android:id="#+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="bottom"
android:visibility="visible"
app:tabMode="scrollable"
app:tabGravity="center"
app:layout_scrollFlags="enterAlways"
app:tabTextColor="#ffff11" />
/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fefefe"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/viewPager"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
</android.support.v4.view.ViewPager>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
I want like, scroll the items in the viewpager then should expand and collapse the "CollapsingToolbarLayout"
You can solve this by below code
NestedScrollView scrollView = (NestedScrollView) findViewById (R.id.nest_scrollview);
scrollView.setFillViewport (true);
I'm trying to make a wrap_content RecyclerView, but it doesn't work.
I write this xml code:
<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="true"
tools:context="br.com.moviee.activity.ItemActivity">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar_layout"
android:layout_width="match_parent"
android:background="#android:color/transparent"
android:fitsSystemWindows="true"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp"
app:titleEnabled="true"
android:fitsSystemWindows="true">
<com.facebook.drawee.view.SimpleDraweeView
android:transitionName="#string/transition_poster"
android:id="#+id/poster"
android:layout_width="match_parent"
android:layout_height="400dp"
android:scaleType="centerCrop"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax"/>
<View
android:id="#+id/collapsing_comp"
android:layout_gravity="bottom"
android:layout_width="match_parent"
android:layout_height="140dp" />
<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/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="#+id/scroll"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<include layout="#layout/content_item" />
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_anchor="#id/app_bar_layout"
app:layout_anchorGravity="bottom|right|end"
android:layout_margin="#dimen/fab_margin"
app:srcCompat="#android:drawable/ic_dialog_email" /></android.support.design.widget.CoordinatorLayout>
My RecyclerView Item xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.facebook.drawee.view.SimpleDraweeView
android:id="#+id/thumb_trailer"
android:scaleType="centerCrop"
android:layout_margin="1dp"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageView
android:layout_gravity="center"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:src="#drawable/ic_play_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content" /></RelativeLayout>
And the content Layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/content_item"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:layout_height="wrap_content"
tools:context="br.com.moviee.activity.ItemActivity"
tools:showIn="#layout/activity_item">
<include layout="#layout/card_main_information" />
<include layout="#layout/card_overview" />
<TextView
android:background="#android:color/white"
android:textStyle="bold"
android:textSize="14sp"
android:padding="16dp"
android:text="#string/title_trailer"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v7.widget.RecyclerView
android:background="#android:color/white"
android:id="#+id/grid_trailer"
android:layout_width="match_parent"
android:layout_height="wrap_content" /></LinearLayout>
And write this java code:
private void configGrid() {
if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT)
layoutManager = new GridLayoutManager(this, Youtube.COLUM_NUMBER_PORTRAIT);
else
layoutManager = new GridLayoutManager(this, Youtube.COLUM_NUMBER_LANDSCAPE);
trailerGrid.setLayoutManager(layoutManager);
TrailerGridAdapter adapter = new TrailerGridAdapter(this);
trailerGrid.setAdapter(adapter);
trailerGrid.setHasFixedSize(true);
trailerGrid.setNestedScrollingEnabled(false);
}
I don't know why my Wrap_content RecyclerView doesn't work.
I have a typical listview with an edittext and a button at the bottom of the activity.
When I click onto the edittext, the soft keyboard appears, I am able to scroll the items in the listview but it re-sizes my background image.
I have tried android:windowSoftInputMode="adjustResize" but no difference.
I have tried android:windowSoftInputMode="adjustPan". The image does not get squashed, the whole layout shifts upwards and I lose the title bar. I can only scroll the list if the list items exceed the layout size.
Basically, I want to maintain the title bar, retain the background image without re-sizing and allow scrolling of list items. Anyone managed to do this? Thanks!
for listview you need to use
android:isScrollContainer="false"
and add this to your activity in manifest.xml
android:windowSoftInputMode="adjustPan"
I have tried so may solutions for solving this problem. android:windowSoftInputMode="adjustPan" will make your whole screen shift with keyboard. Generally we have a title of the screen on the top. Using this flag it will also go out of the visible area, which make bad user experience. I use android:windowSoftInputMode="adjustResize" This will resize the whole screen but it will cause the same problem #Maurice state in the question.
So here is my final solution:
In Manifest
android:windowSoftInputMode="adjustResize|stateAlwaysHidden"
In XMl
Dont Set any background here.And keep your view under ScrollView
In Java
You need to set the background to window:
getWindow().setBackgroundDrawableResource(R.drawable.bg_wood) ;
Go to the Androidmanifest.xml and:
activity name="activityname" android:windowSoftInputMode="stateVisible|adjustPan"
There is no way to prevent the soft keyboard from resizing a background image.
Use this scaleType(matrix) and prepare a suitable image.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/RelativeLayoutchat"
>
<LinearLayout
android:orientation="horizontal"
android:gravity ="clip_horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true">
<ImageView
android:gravity ="clip_horizontal"
android:id="#+id/chat_bak_img"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="matrix">
</ImageView>
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ListView
android:id="#+id/chat"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:transcriptMode="alwaysScroll"
android:divider="#000000"
android:clickable="false"
android:layout_weight="9"
android:cacheColorHint="#00000000"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1"
style="#android:style/ButtonBar"
android:gravity="center"
android:paddingLeft="3dip"
android:paddingTop="3dip"
android:paddingRight="3dip">
<EditText
android:id="#+id/chatMsg"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:maxLines="5"
android:enabled="true"
android:textSize="17sp"
android:maxLength="150"/>
<Button
android:id="#+id/sendMsg"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/send_withSpace"
android:layout_weight="4"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Use android:windowSoftInputMode="adjustResize" and simply wrap your background ImageView in a ScrollView.
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbars="none"
android:overScrollMode="never">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</ScrollView>
I have the same problem with imageview resize while keyboard up i have solved with manifest android:windowSoftInputMode="adjustPan" and following is the layout example in my case
i.e frg_write_social:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/frg_writeyourpost_ll_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:fitsSystemWindows="true"
android:isScrollContainer="false"
android:scrollbars="none" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/frg_writeyourpost_rl_top"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/frg_writeyourpost_ll_bottum"
android:layout_alignParentTop="true"
android:minHeight="400dip" >
<ImageView
android:id="#+id/frg_writyourpost_iv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:adjustViewBounds="true"
android:scaleType="fitXY" />
</RelativeLayout>
<LinearLayout
android:id="#+id/frg_writeyourpost_ll_bottum"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:padding="10dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:background="#android:color/white"
android:gravity="center"
android:orientation="vertical"
android:padding="10dp" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:gravity="center"
android:text="Write your post"
android:textColor="#727F8D"
android:textSize="10sp" />
<com.example.views.CustomEditText
android:id="#+id/frg_writeyourpost_et_message"
android:layout_width="match_parent"
android:layout_height="#dimen/slide_image"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#null"
android:inputType="textMultiLine"
android:maxHeight="#dimen/slide_image"
android:maxLines="3"
android:textSize="11sp" >
</com.example.views.CustomEditText>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/frg_writeyourpost_tv_totalcharacter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="0"
android:textColor="#727F8D"
android:textSize="8sp" />
<TextView
android:id="#+id/frg_writeyourpost_tv_characterLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:gravity="center"
android:text="character"
android:textColor="#727F8D"
android:textSize="8sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal" >
<RadioGroup
android:id="#+id/frg_writepost_fbtw_rggroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/frg_writepost_rb_facebook"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/fb_check_selector"
android:button="#android:color/transparent"
android:gravity="center"
android:padding="10dip"
android:text="#string/post_for_facebook"/>
<View
android:layout_width="5dip"
android:layout_height="match_parent"
android:background="#android:color/transparent"/>
<RadioButton
android:id="#+id/frg_writepost_rb_twitter"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/tw_check_selector"
android:button="#android:color/transparent"
android:gravity="center"
android:padding="10dip"
android:text="#string/post_for_twitter"/>
</RadioGroup>
</LinearLayout>
</LinearLayout>
</LinearLayout>
if there is possible to load image dynamically you can resize image with picaaso while load in imageview
Use ImageView with fill_parent and centerCrop attributes in RelativeLayout. Like this;
<RelativeLayout 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"
>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="#drawable/yazisma_arka_plan"
android:scaleType="centerCrop"
/>
<ListView
android:id="#+id/messages_view"
android:layout_width="fill_parent"...
I read a lot of answers over StackOverflow and took some from many to make my app works:
No ScrollView at all in my activity_main.xml
In AndroidManifest.xml added this attribute to the
<activity android:name=".MainActivity" ...>
tag:
android:windowSoftInputMode="adjustResize"
In MainActivity.java inside onCreate()
I added getWindow().setBackgroundDrawableResource(R.drawable.app_bg);
It works for me when all the other solutions I've tried didn't.
If you got up to here, I hope it'll work for you too.
Er, let me see ... pictures first!
The layout file act_login.xml.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/login_bkgd"
android:orientation="vertical"
android:paddingLeft="25dp"
android:paddingRight="25dp"
>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#0fff"
android:scrollbars="none"
android:listSelector="#0fff"
android:divider="#0fff"
android:dividerHeight="0dp"
android:isScrollContainer="true"
/>
<!--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!-->
<!--android:isScrollContainer="true"-->
<!--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!-->
<LinearLayout
android:id="#+id/loginItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
>
<ImageView
android:id="#+id/loginLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="35dp"
android:layout_marginTop="35dp"
android:scaleType="fitCenter"
android:src="#drawable/logo"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingBottom="35dp"
>
<View
android:layout_width="0dp"
android:layout_height="1px"
android:layout_weight="1"
android:background="#Ffff"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:text="WELCOME"
android:textColor="#Ffff"
android:textSize="14sp"
/>
<View
android:layout_width="0dp"
android:layout_height="1px"
android:layout_weight="1"
android:background="#Ffff"
/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#drawable/login_et_long"
android:gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
>
<TextView
android:layout_width="60dp"
android:layout_height="wrap_content"
android:background="#null"
android:text="账号:"
android:textColor="#Ffff"
android:textSize="16sp"
/>
<EditText
android:id="#+id/loginUsername"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#null"
android:hint="请输入手机号"
android:imeOptions="actionNext"
android:inputType="text"
android:singleLine="true"
android:textColor="#F000"
android:textSize="16sp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginBottom="45dp"
android:layout_marginTop="10dp"
android:background="#drawable/login_et_long"
android:gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
>
<TextView
android:layout_width="60dp"
android:layout_height="wrap_content"
android:background="#null"
android:text="密码:"
android:textColor="#Ffff"
android:textSize="16sp"
/>
<EditText
android:id="#+id/loginPassword"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#null"
android:hint="请输入密码"
android:imeOptions="actionGo"
android:inputType="textPassword"
android:singleLine="true"
android:textColor="#F000"
android:textSize="16sp"
/>
</LinearLayout>
<TextView
android:id="#+id/login"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#drawable/login_button"
android:gravity="center"
android:padding="10dp"
android:text="#string/str_login"
android:textColor="#Ffff"
android:textSize="19sp"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
The related Java codes.
EditText etUsername, etPassword;
EditText etFocus;
ViewGroup base;
int mSelection;
#Override
protected void onCreate(Bundle savedInstanceState) {
base=(ViewGroup)getLayoutInflater().inflate(R.layout.act_login, null);
setContentView(base);
getWindow().setBackgroundDrawable(base.getBackground());
base.setBackground(null);
super.onCreate(savedInstanceState);
}
#Override
protected void initViews() {
etUsername=(EditText)findViewById(R.id.loginUsername);
etPassword=(EditText)findViewById(R.id.loginPassword);
final ViewGroup item=(ViewGroup)findViewById(R.id.loginItem);
base.removeView(item);
final View[] items=new View[item.getChildCount()];
for(int i=0; i<item.getChildCount(); i++) items[i]=item.getChildAt(i);
item.removeAllViews();
ListView lv=(ListView)base.getChildAt(0);
lv.setAdapter(new BaseAdapter() {
public View getView(int i, View v, ViewGroup vg) {
if(etFocus!=null && getCurrentFocus()!=etFocus){
etFocus.requestFocus();
etFocus.setSelection(mSelection);
//etFocus=null;
}
return items[i];
}
public int getCount() {return items.length;}
public Object getItem(int position) {return null;}
public long getItemId(int position) {return 0;}
});
/*View.OnTouchListener listener=new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent e) {
if(e.getAction()!=MotionEvent.ACTION_UP) return false;
etFocus=(EditText)v;
mSelection=etFocus.getSelectionEnd();
ZZ.z("_________________ mSelection="+mSelection);
return false;
}
};
etUsername.setOnTouchListener(listener);
etPassword.setOnTouchListener(listener);*/
View.OnFocusChangeListener listener1=new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if(!hasFocus){
etFocus=(EditText)v;
mSelection=etFocus.getSelectionStart();
ZZ.z("_________________ mSelection="+mSelection);
}
}
};
etUsername.setOnFocusChangeListener(listener1);
etPassword.setOnFocusChangeListener(listener1);
}
The AndroidManifest part.
<activity
android:name=".ui.activity.ActLogin"
android:label="#string/str_login"
android:theme="#style/myTheme"
/>
<!--android:windowSoftInputMode="adjustResize"-->
The style part.
<style name="myTheme" parent="#android:style/Theme.Light.NoTitleBar">
<item name="android:windowTranslucentStatus">true</item>
</style>
This code doesn't work for me:
android:windowSoftInputMode="adjustResize"
But this does work:
android:windowSoftInputMode="adjustPan"
For those who aren't get it:
double ckeck if your xml already has a #drawable setted (this was the error for me, i was setting via android manifest but it was already setted on the root of xml)
after that create a theme style with background:
<style name="AppThemeWBackgroundG" parent="AppTheme">
<item name="android:windowBackground">#drawable/background_com_gradiente</item>
</style>
Then in your activity on AndroidManifest.xml:
<activity
android:name=".TelaLoginFuncionario"
android:windowSoftInputMode="adjustResize|stateAlwaysVisible"
android:theme="#style/AppThemeWBackgroundG"
android:fitsSystemWindows="true"
/>
and that's it: the activity enter in a screen with the keyboard up, resizing up the items and the background stays at normal size
all you need to do is to set the background gravity to the top
<item android:drawable="#drawable/background_image" android:gravity="top"/>
Here is tutorial