Animation a layout from bottom to top with fade in - android

I want a animation that first FadeIn the TextView with id Symbol_no from Bottom to Top Then FadeIn other View on the screen.
symbolnotextview.animate().setDuration(duration).
scaleX(1).scaleY(1).
translationX(0).translationY(0).
setInterpolator(sDecelerator).
withEndAction(new Runnable() {
public void run() {
// Animate the description in after the image animation
// is done. Slide and fade the text in from underneath
// the picture.
mTextView.setTranslationY(-mTextView.getHeight());
mTextView.animate().setDuration(duration/2).
translationY(0).alpha(1).
setInterpolator(sDecelerator);
}
});
But i think this is not what i mean to do .
Here is the XML of the design
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="100"
android:id="#+id/toplevel">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:layout_weight="15"
android:background="#drawable/borderframe">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:padding="5dp"
android:src="#drawable/abc_btn_radio_to_on_mtrl_015"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="21477"
android:padding="5dp"
android:gravity="center"
android:background="#drawable/border"
android:id="#+id/Symbol_no"
/>
</LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:text="Rohit Shrestha"
android:layout_weight="20"
android:textSize="30sp"
android:gravity="center"
android:id="#+id/name"
/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="20"
android:paddingLeft="25dp"
android:paddingRight="25dp"
android:id="#+id/parentblock">
<TextView
android:layout_width="0dp"
android:layout_height="fill_parent"
android:text="Block"
android:textSize="30sp"
android:gravity="center"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/block_no"
android:background="#drawable/border"/>
<TextView
android:layout_width="120dp"
android:layout_height="fill_parent"
android:text="7"
android:gravity="center"
android:textStyle="bold"
android:layout_alignParentRight="true"
android:textSize="40sp"
android:id="#+id/block_no"
android:background="#drawable/border"/>
</RelativeLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="10"
android:weightSum="100"
android:paddingLeft="40dp"
android:paddingRight="40dp"
android:paddingTop="30dp"
android:id="#+id/class_container"
>
<LinearLayout
android:layout_weight="40"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#drawable/border"
android:gravity="center"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Class"
android:textSize="30dp"
android:gravity="center"
android:id="#+id/class_text"
/>
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="#+id/room_no"
android:textSize="25dp"
android:gravity="center"
android:text="8"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_weight="40"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#drawable/border"
android:gravity="center"
android:layout_marginLeft="15dp">
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Seat"
android:gravity="center"
android:textSize="30dp"
android:id="#+id/Seat_text"
/>
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="8"
android:gravity="center"
android:id="#+id/Seat_No"
android:textSize="25dp"
/>
</LinearLayout>
</LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="15dp"
android:text="Good Luck"
android:gravity="center"
android:id="#+id/display_notification"
android:layout_weight="10"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/Time_Left"
android:text="5 hours to go"
android:gravity="center"
android:textSize="20dp"
android:layout_weight="10"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="10dp"
android:text="15 july,2015"
android:gravity="center"
android:layout_weight="10"/>
This is the output :

Try this:
Button btn = (Button)findViewById(R.id.Symbol_no);
DisplayMetrics dis = getResources().getDisplayMetrics();
TranslateAnimation anim = new TranslateAnimation(0, 0, dis.heightPixels, 0);
anim.setDuration(1000);
anim.setAnimationListener(new AnimationListener()
{
#Override
public void onAnimationStart(Animation arg0)
{
}
#Override
public void onAnimationRepeat(Animation arg0)
{
}
#Override
public void onAnimationEnd(Animation arg0)
{
// show whatever you want to show after animation is finished.
}
});
btn.startAnimation(anim);

Related

How to click button inside listview

I know this problem already asked many times but i still can't get effective way for solving this. I try for use ListView with clickable/editable widget and Android : How to set onClick event for Button in List item of ListView as reference but the result is i need click button several time for executing my program. Here my program
LeadActivity.xml
<?xml version="1.0" encoding="utf-8"?>
<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"
android:orientation="vertical"
tools:context=".LeadSalesActivity">
<LinearLayout
android:background="#E9ECEB"
android:layout_margin="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/b_menusamping2"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="20dp"
android:background="#drawable/menu_button"
android:backgroundTint="#27D01B"/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="10dp"
android:layout_weight="1"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome,"
android:textSize="20sp"
android:textStyle="italic"
android:textColor="#android:color/black"/>
<TextView
android:id="#+id/t_username3"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="Rizaldi"
android:textColor="#android:color/black"
android:textSize="25sp"
android:textStyle="bold"
android:fontFamily="#font/action_man_bold"/>
</LinearLayout>
<LinearLayout
android:id="#+id/linear_refresh2"
android:layout_margin="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/white">
<ImageView
android:backgroundTint="#27D01B"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_margin="10dp"
android:background="#drawable/icon_update"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_marginLeft="20dp"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Lead"
android:textColor="#android:color/black"
android:textSize="20sp"/>
<TextView
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="("
android:textSize="20sp"
android:textColor="#android:color/black"/>
<TextView
android:textStyle="bold"
android:id="#+id/count_lead"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="100"
android:textColor="#android:color/black"
android:textSize="20sp"/>
<TextView
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=")"
android:textSize="20sp"
android:textColor="#android:color/black"/>
<Button
android:id="#+id/btn_add"
android:layout_marginRight="20dp"
android:backgroundTint="#android:color/holo_blue_light"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tambah Lead"
android:textAllCaps="false"/>
</LinearLayout>
<LinearLayout
android:padding="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
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:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tanggal"
android:textColor="#android:color/black"
android:textSize="20sp"/>
<TextView
android:layout_marginLeft="30dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Lead"
android:textSize="20sp"
android:textColor="#android:color/black"/>
<TextView
android:layout_marginLeft="40dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Telp"
android:textColor="#android:color/black"
android:textSize="20sp"/>
</LinearLayout>
<ListView
android:id="#+id/listviewlead"
tools:listitem="#layout/c_lead"
android:layout_width="match_parent"
android:layout_height="400dp"
android:layout_weight="1" />
</LinearLayout>
</ScrollView>
</LinearLayout>
<LinearLayout
android:layout_marginTop="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:id="#+id/back6"
android:layout_marginRight="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="back"/>
</LinearLayout>
c_lead.xml
<?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="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/t_tgl"
android:focusable="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="Tgl"
android:textSize="15sp"
android:textStyle="italic"
android:textColor="#000000" />
<TextView
android:id="#+id/t_lead4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="Lead"
android:textSize="15sp"
android:textColor="#000000" />
<TextView
android:id="#+id/t_numberphone"
android:focusable="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:gravity="right"
android:text="No.Telp"
android:textSize="15sp"
android:textColor="#android:color/black"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<LinearLayout
android:id="#+id/btn_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/kotak_abu"
android:layout_marginTop="5dp">
<ImageButton
android:layout_margin="10dp"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="#drawable/pencil_icon"/>
</LinearLayout>
<LinearLayout
android:id="#+id/btn_delete"
android:layout_marginLeft="3dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/kotak_abu"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp">
<ImageButton
android:layout_margin="10dp"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="#drawable/delete_icon"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/t_alamat"
android:focusable="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="Alamat"
android:textColor="#android:color/black"
android:textSize="15sp"
android:layout_marginLeft="20dp"/>
</LinearLayout>
MyAdapter
public View getView(final int _position, View _v, ViewGroup _container) {
LayoutInflater _inflater = (LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View _view = _v;
if (_view == null) {
_view = _inflater.inflate(R.layout.c_lead, null);
}
final HashMap<String, Object> hashMap = _data.get(_position);
final TextView t_tanggal = (TextView) _view.findViewById(R.id.t_tgl);
final TextView t_lead = (TextView) _view.findViewById(R.id.t_lead4);
final TextView t_alamat = (TextView) _view.findViewById(R.id.t_alamat);
final TextView t_numberphone = (TextView) _view.findViewById(R.id.t_numberphone);
final LinearLayout btn_edit = (LinearLayout) _view.findViewById(R.id.btn_edit);
final LinearLayout btn_delete = (LinearLayout) _view.findViewById(R.id.btn_delete);
String dateString = _data.get(_position).get("create_date").toString().replace("-","");
SimpleDateFormat format1 = new SimpleDateFormat("yyyyMMddHHmm");
format1.setTimeZone(TimeZone.getTimeZone("GMT+7"));
SimpleDateFormat format2 = new SimpleDateFormat("dd-MM-yyyy");
try {
Date date = format1.parse(dateString);
String dateFinal = format2.format(date);
t_tanggal.setText(String.valueOf((long)(_position + 1)).concat(".").concat(dateFinal));
} catch (ParseException e) {
e.printStackTrace();
}
t_lead.setText(_data.get((int)_position).get("type").toString());
t_alamat.setText(_data.get((int)_position).get("street").toString());
if (_data.get((int)_position).get("mobile").toString().equals(true)){
t_numberphone.setText("Tanpa Nomor");
} else {
t_numberphone.setText(_data.get((int)_position).get("phone").toString());
}
btn_edit.setFocusable(false);
btn_edit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
i.setClass(getApplicationContext(), AddLeadSalesActivity.class);
startActivity(i);
}
});
btn_delete.setFocusable(false);
btn_delete.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(getApplicationContext(), "Data Tidak Bisa Dihapus", Toast.LENGTH_SHORT).show();
}
});
return _view;
}
Is there any mistake inside my program? How to solve this?

EditText OnFocusChangeListener() doesn't hide cursor and view

I made an EditText OnFocusChangeListener that supposedly hides the cursor and another view when it's not in focus (i.e. clicking anywhere on the screen aside from the EditText will hide those items). Clicking on the EditText is the only time that will display them.
This is my OnFocusChangeListener for my EditText pageTitle:
pageTitle.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View view, boolean b) {
if(b) {
pageTitle.setCursorVisible(true);
saveCancelBar.setVisibility(View.VISIBLE);
} else {
pageTitle.setCursorVisible(false);
saveCancelBar.setVisibility(View.GONE);
}
}
});
I also made an OnclickListener:
pageTitle.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
pageTitle.setCursorVisible(true);
saveCancelBar.setVisibility(View.VISIBLE);
}
});
The OnClickListener works but not the OnFocusListener. Ideally, pageTitle's cursor and saveCancelBar are initially hidden and will only appear when pageTitle is clicked.
This 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"
tools:ignore="missingPrefix"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
tools:context="app.wanderast.activity.AddPhotoActivity">
<LinearLayout
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:orientation="horizontal">
<TextView
android:id="#+id/back_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/arrow_left"
android:textSize="20sp"
android:clickable="true"
android:textColor="#color/black" />
</LinearLayout>
<LinearLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_below="#id/toolbar"
android:orientation="vertical">
<EditText
android:id="#+id/title"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="36dp"
android:background="#color/transparent"
android:maxLength="64"
android:privateImeOptions="nm"
android:inputType="textNoSuggestions|textMultiLine"
android:cursorVisible="false"
app:autoSizeTextType="uniform"
app:autoSizeMinTextSize="16sp"
app:autoSizeMaxTextSize="24sp"
app:autoSizeStepGranularity="4sp"
android:textColor="#color/grey700"/>
<View
android:layout_width="100dp"
android:layout_height="2dp"
android:layout_marginTop="3dp"
android:background="#color/grey700"
/>
<LinearLayout
android:id="#+id/sort"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/header"
android:layout_marginTop="20dp"
android:clickable="true"
android:gravity="bottom"
android:orientation="horizontal"
android:visibility="gone">
<TextView
android:id="#+id/sort_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="3dp"
android:text="List View"
android:textColor="#color/grey700"
android:textSize="14sp"/>
<TextView
android:id="#+id/sort_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/chevron_circle_down"
android:textColor="#color/grey700"
android:textSize="14sp"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/linearLayout">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/add_photo_layout"
android:layout_marginTop="150dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:layout_centerInParent="true">
<TextView
android:id="#+id/placeholder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginEnd="40dp"
android:layout_marginBottom="30dp"
android:background="#null"
android:minLines="0"
android:text="Add your first travel moment to your story"
android:textAlignment="center"
android:textColor="#color/black"
android:textSize="20sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">
<LinearLayout
android:id="#+id/capture_photo_button"
android:layout_marginBottom="15dp"
android:paddingStart="5dp"
android:paddingEnd="5dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:layout_width="170dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center|center_vertical"
android:background="#drawable/green_pill_thick">
<TextView
android:id="#+id/capture_photo_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text="#string/camera"
android:layout_gravity="center_horizontal|center_vertical"
android:textColor="#color/green500"
android:layout_marginEnd="5dp"/>
<TextView
android:id="#+id/capture_photo_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Capture Moment"
android:layout_gravity="center_horizontal|center_vertical"
android:textColor="#color/green500"
android:textAlignment="center"
android:textSize="14sp"/>
</LinearLayout>
<LinearLayout
android:id="#+id/add_photo_button"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingStart="5dp"
android:paddingEnd="5dp"
android:layout_width="170dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center|center_vertical"
android:background="#drawable/blue_pill_thick">
<TextView
android:id="#+id/add_photo_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text="#string/photo"
android:layout_gravity="center_horizontal|center_vertical"
android:textColor="#color/blue500"
android:layout_marginEnd="5dp"/>
<TextView
android:id="#+id/add_photo_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add from Gallery"
android:layout_gravity="center_horizontal|center_vertical"
android:textColor="#color/blue500"
android:textAlignment="center"
android:textSize="14sp"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/list_view_layout"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="150dp"
android:paddingBottom="50dp">
<ListView
android:id="#+id/list_view_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll">
</ListView>
</RelativeLayout>
</LinearLayout>
<!--Navbar-->
<LinearLayout
android:id="#+id/photo_story_navbar"
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="#drawable/navbar"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:visibility="gone">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="right"
android:paddingStart="15dp"
android:orientation="horizontal"
android:layout_marginEnd="10dp">
<!-- Take Photo Button -->
<LinearLayout
android:id="#+id/nav_capture_button"
android:layout_width="84dp"
android:layout_height="32dp"
android:paddingStart="10dp"
android:orientation="horizontal"
android:background="#drawable/green_pill_button"
android:layout_gravity="center_vertical"
android:gravity="center|center_vertical"
android:paddingEnd="10dp"
android:clickable="true">
<TextView
android:id="#+id/nav_capture_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:text="#string/camera"
android:textColor="#color/green500"
android:layout_gravity="center_horizontal|center_vertical"
android:paddingEnd="5dp"/>
<TextView
android:id="#+id/nav_capture_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Capture"
android:layout_gravity="center_horizontal|center_vertical"
android:textColor="#color/green500"
android:textAlignment="center"
android:textSize="12sp"/>
</LinearLayout>
<!-- Add from Gallery Button -->
<LinearLayout
android:id="#+id/nav_gallery_button"
android:layout_width="84dp"
android:layout_height="32dp"
android:paddingStart="10dp"
android:layout_marginLeft="5dp"
android:orientation="horizontal"
android:background="#drawable/blue_pill"
android:layout_gravity="center_vertical"
android:gravity="center|center_vertical"
android:paddingEnd="10dp"
android:clickable="true">
<TextView
android:id="#+id/nav_gallery_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:text="#string/photo"
android:textColor="#color/blue500"
android:layout_gravity="center_horizontal|center_vertical"
android:paddingEnd="5dp"/>
<TextView
android:id="#+id/nav_gallery_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Gallery"
android:layout_gravity="center_horizontal|center_vertical"
android:textColor="#color/blue500"
android:textAlignment="center"
android:textSize="12sp"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="right"
android:paddingEnd="15dp"
android:orientation="horizontal">
<!-- Review button -->
<LinearLayout
android:id="#+id/nav_review_button"
android:layout_width="84dp"
android:layout_height="32dp"
android:paddingStart="10dp"
android:orientation="horizontal"
android:background="#drawable/red_500_pill"
android:layout_gravity="right"
android:gravity="center|center_vertical"
android:paddingEnd="10dp"
android:clickable="true">
<TextView
android:id="#+id/nav_review_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Review"
android:layout_gravity="center_horizontal|center_vertical"
android:textColor="#color/red500"
android:textAlignment="center"
android:textSize="12sp"/>
<TextView
android:id="#+id/nav_review_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:text="#string/angle_double_right"
android:textColor="#color/red500"
android:layout_gravity="center_horizontal|center_vertical"
android:paddingStart="5dp"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:id="#+id/save_cancel_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/linearLayout"
android:layout_alignParentStart="true"
android:background="#drawable/black_border_top"
android:visibility="gone">
<RelativeLayout
android:id="#+id/save_title_btn"
android:clickable="true"
android:layout_width="84dp"
android:layout_height="32dp"
android:layout_alignParentRight="true"
android:background="#drawable/blue_pill"
android:layout_marginRight="15dp"
android:layout_marginTop="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="fill"
android:text="Save Title"
android:textSize="12sp"
android:textColor="#2196F3"/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/cancel_title_btn"
android:layout_width="84dp"
android:layout_height="32dp"
android:clickable="true"
android:layout_alignParentRight="true"
android:background="#drawable/grey_700_pill"
android:layout_marginRight="105dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Cancel"
android:layout_gravity="fill"
android:textSize="12sp"
android:textColor="#616161" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
If you check the definition of onFocusChange(View v, boolean hasFocus) you will notice that your code must change like this:
pageTitle.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View view, boolean hasFocus) {
if(!hasFocus) {
pageTitle.setCursorVisible(true);
saveCancelBar.setVisibility(View.VISIBLE);
} else {
pageTitle.setCursorVisible(false);
saveCancelBar.setVisibility(View.GONE);
}
}
});
This is the code for checking the soft keyboard visibility in Android
public class MainActivity extends AppCompatActivity
{
public static String TAG = MainActivity.class.getSimpleName();
private TextView saveCancelBar;
private EditText pageTitle;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setListenerToRootView();
saveCancelBar = (TextView) findViewById(R.id.cancel_bar);
pageTitle = (EditText) findViewById(R.id.title);
pageTitle.setOnFocusChangeListener(new View.OnFocusChangeListener()
{
#Override
public void onFocusChange(View view, boolean hasFocus)
{
...
}
});
}
public void setListenerToRootView()
{
final View activityRootView = getWindow().getDecorView().findViewById(android.R.id.content);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener()
{
#Override
public void onGlobalLayout()
{
Rect r = new Rect();
activityRootView.getWindowVisibleDisplayFrame(r);
int screenHeight = activityRootView.getRootView().getHeight();
// r.bottom is the position above soft keypad or device button.
// if keypad is shown, the r.bottom is smaller than that before.
int keypadHeight = screenHeight - r.bottom;
Log.e(TAG, "keypadHeight = " + keypadHeight);
if (keypadHeight > screenHeight * 0.15) {
// 0.15 ratio is perhaps enough to determine keypad height.
Toast.makeText(getApplicationContext(), "Gotcha!!! softKeyboard open", Toast.LENGTH_SHORT).show();
} else {
// keyboard is closed
Toast.makeText(getApplicationContext(), "Gotcha!!! softKeyboard closed", Toast.LENGTH_SHORT).show();
saveCancelBar.setVisibility(View.GONE);
}
}
});
}
}
I think you forgot to add focusableInTouchMode. Add focusableInTouchMode to your editText to get focused on touching the view.
android:focusableInTouchMode="true"

Android custom dialog displays extra space

My custom dialog adds extra space after the Cancel and Save button. I have made a couple of custom dialogs in this app, but this problem appears only in this case. I've colored the view's background to blue, so I think it should be okay.
layout:
<?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="wrap_content"
android:background="#android:color/holo_blue_dark">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="#dimen/activity_vertical_margin"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:gravity="center_horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/black"
android:text="#string/mo"/>
<CheckBox
android:id="#+id/cbMo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal"
android:layout_marginLeft="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/black"
android:text="#string/tu"/>
<CheckBox
android:id="#+id/cbTu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal"
android:layout_marginLeft="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/black"
android:text="#string/we"/>
<CheckBox
android:id="#+id/cbWe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal"
android:layout_marginLeft="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/black"
android:text="#string/th"/>
<CheckBox
android:id="#+id/cbTh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal"
android:layout_marginLeft="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/black"
android:text="#string/fr"/>
<CheckBox
android:id="#+id/cbFr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:layout_marginTop="#dimen/activity_vertical_margin"
android:gravity="center_horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:layout_marginRight="10dp"
android:text="#string/repeat_every"
android:textColor="#android:color/black"
android:gravity="right"
android:layout_gravity="center_vertical"/>
<Spinner
android:id="#+id/spRecurrence"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:prompt="#string/repeat_every"
android:layout_gravity="center_vertical"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:layout_marginTop="#dimen/activity_vertical_margin">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:layout_marginRight="10dp"
android:text="#string/starts_on"
android:textColor="#android:color/black"
android:gravity="right"/>
<TextView
android:id="#+id/tvDate"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:text="#string/pick_a_date"
android:drawableRight="#drawable/ic_calendar"
android:gravity="center_vertical"/>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0.2"
android:visibility="visible"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:layout_marginTop="#dimen/activity_vertical_margin">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:gravity="right"
android:layout_marginRight="10dp"
android:textColor="#android:color/black"
android:text="#string/recurrences_colon"/>
<EditText
android:id="#+id/etNumber"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:inputType="number"/>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0.3"
android:visibility="invisible"/>
</LinearLayout>
<TextView
android:id="#+id/tvError"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#android:color/holo_red_dark"
android:visibility="visible"
android:text="Error text"/>
</LinearLayout>
Displaying the dialog:
Context context = getContext();
final NewRecurrencesDialogView recurrencesDialogView = new NewRecurrencesDialogView(context, subject);
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setView(recurrencesDialogView)
.setTitle(R.string.set_recurrence)
.setPositiveButton(R.string.save, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) { }
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
}
});
final Dialog dialog = builder.create();
dialog.setCancelable(false);
dialog.show();
((AlertDialog)dialog).getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
ArrayList<Teaching> newRecurrences = recurrencesDialogView.saveRecurrences();
if (newRecurrences != null) {
recurrences.addAll(newRecurrences);
Collections.sort(recurrences, new Comparator<Teaching>() {
#Override
public int compare(Teaching lhs, Teaching rhs) {
if (lhs.getBegin() < rhs.getBegin())
return -1;
else
return 1;
}
});
updateListViewAdapter();
dataChangedListener.setChanged(true);
dialog.dismiss();
}
}
});
((AlertDialog)dialog).getButton(AlertDialog.BUTTON_NEUTRAL).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
}
});
I've compared the layout file with the other dialog's files, but can't figure out where the problem is.
I think the problem is with the android:layout_weight you set for your view.
Try change your:
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0.2"
android:visibility="visible"/>
To this:
<View
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:visibility="visible"/>
I am not really sure what you trying to achieve, but think this will show you the direction (hopefully the right one).

add blink to customized listview Item?

i have created a listview contains multiple items, and i added a border to those items so it would look like this:
because of this customized border the original blink of an item get blocked so it doesn't appear, and i've tried to add a blink through animation but there is too much delay and too much work on the main thread, i also used animation inside threads but it is the same with the delay thing, which force me to forget about animation so is there anyway that i can make the item blink when its clicked without using animation or with using it but in an efficient way and by the way i used blink animation inside my onItemClickListener you can find it in the code below:
onItemClickListener that handle the blink:
dataList.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, final View arg1,
final int arg2, long arg3) {
// TODO Auto-generated method stub
tvWarningNoEmp.setVisibility(View.GONE);
// adding blink
final Animation animation = new AlphaAnimation(
1, 0); // Change
// alpha
// from
// fully
// visible
// to
// invisible
animation.setDuration(100); // duration - half a
// second
animation
.setInterpolator(new LinearInterpolator()); // do
// not
// alter
// animation
// rate
animation.setRepeatCount(Animation.INFINITE); // Repeat
// animation
// infinitely
animation.setRepeatMode(Animation.REVERSE);
arg1.startAnimation(animation);
// blink one time timer
new CountDownTimer(100, 100) {// CountDownTimer(edittext1.getText()+edittext2.getText())
// also parse it to long
public void onTick(long millisUntilFinished) {
// here you can have your logic to set text to
// edittext
}
public void onFinish() {
arg1.clearAnimation();
}
}.start();
// set margins for tickets buttons
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
params.setMargins(0, 0, 30, 0);
bAssign.setLayoutParams(params);
LinearLayout.LayoutParams paramsO = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
paramsO.setMargins(110, 0, 0, 0);
bEmpChat.setLayoutParams(paramsO);
noEmpLayout.setVisibility(LinearLayout.GONE);
empLayout.setVisibility(LinearLayout.VISIBLE);
Employee item = adapter.getItem(arg2);
ivEmpIcon.setBackgroundResource(R.drawable.free);
tvEmpName.setText(" " + item.getEmpName());
tvEmpDetails.setText(" " + item.getEmpDetails());
empLongitude = item.getEmpLongitude();
empLatitude = item.getEmpLatitude();
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(empLatitude, empLongitude))
.zoom(15).build();
googleEmpMap.animateCamera(CameraUpdateFactory
.newCameraPosition(cameraPosition));
MarkerOptions marker = new MarkerOptions().position(
new LatLng(empLatitude, empLongitude)).title(
tvEmpName.getText().toString());
marker.icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_RED));
googleEmpMap.addMarker(marker);
// based on item add info to intent
// hide button directions
bEmpDirections.setVisibility(View.GONE);
// current address
Geocoder geocoder;
List<Address> addresses;
geocoder = new Geocoder(getApplicationContext(), Locale
.getDefault());
try {
addresses = geocoder.getFromLocation(empLatitude,
empLongitude, 1);
String street = addresses.get(0).getAddressLine(0);
String state = addresses.get(0).getAdminArea();
String country = addresses.get(0).getCountryName();
tvEmpCurrentAdd.setText(" " + country + "-" + state
+ "-" + street + " st.");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();}
}
});
ListView Layout:
<?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/redborder" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<Button
android:id="#+id/btnBack"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:background="#drawable/back" />
<TextView
android:id="#+id/tvWarningNoEmp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="choose an employee from here to assign this problem to!"
android:textColor="#FF0000"
android:layout_marginLeft="400dp"
android:visibility="gone"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="40dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_weight="2"
android:background="#drawable/pepsiborder"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="#drawable/blueborder"
android:orientation="horizontal"
android:padding="10dp" >
<ImageView
android:id="#+id/TicketIcon"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center_vertical"
android:layout_weight="0.1" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.7"
android:gravity="center_vertical"
android:orientation="vertical" >
<TextView
android:id="#+id/ticketCat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="7dp"
android:gravity="center_vertical"
android:textColor="#D3D9FF"
android:textSize="17sp" />
</LinearLayout>
</LinearLayout>
<fragment
android:id="#+id/ticketMap"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp" />
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="State:"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#D3D9FF" />
<TextView
android:id="#+id/ticketState"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="#D3D9FF" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ticket No:"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#D3D9FF" />
<TextView
android:id="#+id/ticketNo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="#D3D9FF" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Report Date:"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#D3D9FF" />
<TextView
android:id="#+id/ticketReportDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="#D3D9FF" />
</LinearLayout>
<TextView
android:id="#+id/textView13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Details:"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#D3D9FF" />
<TextView
android:id="#+id/ticketDetails"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="#D3D9FF" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/llBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginBottom="10dp"
android:layout_marginTop="170dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#drawable/blueborder"
android:orientation="horizontal"
android:padding="10dp" >
<Button
android:id="#+id/btnTicketDirections"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_weight="1"
android:background="#drawable/directions" />
<Button
android:id="#+id/btnSolve"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_weight="1"
android:background="#drawable/solve" />
<Button
android:id="#+id/btnOther"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_weight="1"
android:background="#drawable/other" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/llListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="40dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_weight="2"
android:background="#drawable/pepsiborder"
android:orientation="vertical" >
<TextView
android:id="#+id/textView124"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#D3D9FF"
android:text="Free Employees"
android:textSize="30sp"
android:gravity="left"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:textAppearance="?android:attr/textAppearanceLarge" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginLeft="20dp"
>
<ListView
android:id="#+id/listTic"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="5dp"
android:layout_marginTop="20dp"
android:divider="#android:color/transparent"
android:dividerHeight="10dp" >
</ListView>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_weight="2"
android:id="#+id/noempLayout"
android:background="#android:color/transparent"
android:orientation="vertical" >
<TextView
android:text="Please select free Employee to handle this problem!"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:layout_marginTop="300dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="40dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_weight="2"
android:id="#+id/empLayout"
android:background="#drawable/pepsiborder"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="#drawable/blueborder"
android:orientation="horizontal"
android:padding="10dp" >
<ImageView
android:id="#+id/empIcon"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center_vertical"
android:layout_weight="0.1" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.7"
android:gravity="center_vertical"
android:orientation="vertical" >
<TextView
android:id="#+id/empName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="7dp"
android:gravity="center_vertical"
android:textColor="#D3D9FF"
android:textSize="17sp" />
</LinearLayout>
</LinearLayout>
<fragment
android:id="#+id/empMap"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView33"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Current Address:"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#D3D9FF" />
<TextView
android:id="#+id/empAddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="#D3D9FF" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView22"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Details:"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#D3D9FF" />
<TextView
android:id="#+id/empDetails"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="#D3D9FF" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/llBtn2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginTop="220dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#drawable/blueborder"
android:orientation="horizontal"
android:padding="10dp" >
<Button
android:id="#+id/btnEmpDirections"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_weight="1"
android:layout_gravity="center"
android:background="#drawable/directions" />
<Button
android:id="#+id/btnEmpChat"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_weight="1"
android:layout_gravity="center"
android:background="#drawable/chat" />
<Button
android:id="#+id/btnEmpAssign"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_weight="1"
android:layout_gravity="center"
android:background="#drawable/assign" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
ListView Item Layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="280dp"
android:layout_height="90dp"
android:orientation="horizontal"
android:background="#drawable/border"
android:layout_marginTop="10dp"
android:padding="10dp"
>
<ImageView
android:id="#+id/imgIcon"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_weight="0.1"
android:gravity="center_vertical"
/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="0.7"
android:gravity="center_vertical"
>
<TextView
android:id="#+id/txtTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:textSize="17sp"
android:textColor="#D3D9FF"
android:layout_gravity="center_vertical"
android:layout_marginLeft="7dp"
/>
<TextView
android:id="#+id/txtTitle1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_gravity="center_vertical"
android:textSize="13sp"
android:textColor="#D3D9FF"
android:layout_marginLeft="7dp"
/>
</LinearLayout>
</LinearLayout>
Border.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<stroke
android:width="2dip"
android:color="#8D8D8D" />
<corners android:radius="10dip"/>
<solid android:color="#464A4F" />
</shape>
any help is truly appreciated.
If you want a view to blink:
public void blink(final View v) {
v.setBackgroundColor(Color.DKGRAY);
v.animate().setDuration(25).alpha(0).withEndAction(new Runnable() {
#Override
public void run() {
v.setBackgroundResource(R.drawable.standard_key_normal);
v.setAlpha(1);
}
});
}
Send your View to this function, replace the background with whatever drawable or color resource you want. If you want multiple blinks put it in a for loop.
well i figure out how to reduce the delay and add blink effect without using animation and some how it worked for me and there is no more delay, what i did is I've changed the list's linear layouts to relative and that reduced the amount of nested layouts significantly then i added this method:
private void blink(final View v){
final Handler handler = new Handler();
new Thread(new Runnable() {
#Override
public void run() {
int timeToBlink = 1000; //in milissegunds
try{Thread.sleep(timeToBlink);}catch (Exception e) {}
handler.post(new Runnable() {
#Override
public void run() {
if(v == View.VISIBLE){
v.setVisibility(View.INVISIBLE);
}else{
v.setVisibility(View.VISIBLE);
}
blink();
}
});
}
}).start();
then i used it inside onItemClickListener() --> blink(arg1);
worked perfectly for me, also getting the current address was taking too much so i used Async so now there is no delay at all:
Async used as an inner class:
private class LongOperation extends AsyncTask<String, Void, String> {
String all;
#Override
protected String doInBackground(String... params) {
// current address
Geocoder geocoder;
List<Address> addresses;
geocoder = new Geocoder(getApplicationContext(), Locale
.getDefault());
try {
addresses = geocoder.getFromLocation(empLatitude,
empLongitude, 1);
String street = addresses.get(0).getAddressLine(0);
String state = addresses.get(0).getAdminArea();
String country = addresses.get(0).getCountryName();
all="" + country + "-" + state
+ "-" + street + " st.";
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();}
return all;
}
#Override
protected void onPostExecute(String result) {
tvEmpCurrentAdd.setText(all);
}
#Override
protected void onPreExecute() {}
#Override
protected void onProgressUpdate(Void... values) {}
}
and then i called it inside onItemClickListener:
new LongOperation().execute();
hope this will help others that had simillar problem.

Show/Hide top bar like chrome, but with some static content and a listview

First let me give a short introduction and then show you what end goal looks:
So far I've added a scrolllistener to my listactivity, so that I can detect scrolling, though it does not give me any animation on android:animateLayoutChanges="true". So when i change the margin's of the view programmatically, it just does these changes instantly, and not that well, any help is most welcomed.
As you can see in my xml, i place the item I'm going to hide slowly first so other will be above it on the Z-axis.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:lector="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:animateLayoutChanges="true"
android:background="#color/background_greyish">
<LinearLayout
android:id="#+id/disappearingHeaderLabel"
android:layout_width="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_marginTop="60dp"
android:animateLayoutChanges="true"
android:layout_height="50dp"
android:background="#color/solid_white"
android:orientation="horizontal"
android:weightSum="7">
<TextView
android:id="#+id/ProductDetailLabel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:layout_marginLeft="15dp"
android:layout_marginRight="5dp"
android:layout_marginTop="10dip"
android:layout_weight="4"
android:singleLine="true"
android:text="PRODUKTER"
android:textColor="#color/solid_red"
android:textSize="20dp" />
<Button
android:id="#+id/priceChooserButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="15dp"
android:layout_marginTop="10dp"
android:layout_weight="3"
android:background="#drawable/buttonbackground"
android:clickable="true"
android:singleLine="true"
android:text="#string/retailprice"
android:textColor="#android:color/white"
android:textSize="15dp"
android:textStyle="bold" />
</LinearLayout>
<dk.myapp.mobile.views.PageHeaderView
android:id="#+id/header"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"></dk.myapp.mobile.views.PageHeaderView>
<LinearLayout
android:id="#+id/expandingListContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:animateLayoutChanges="true"
android:layout_alignParentLeft="true"
android:layout_marginTop="110dp"
android:layout_above="#+id/paginationBarContainer"
android:orientation="vertical">
<LinearLayout
android:id="#+id/headerLabel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="#color/transparent"
android:orientation="horizontal"
android:weightSum="11">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="3"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/sortAmountLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:singleLine="false"
android:text="1354"
android:textColor="#color/solid_red"
android:textSize="15dp" />
<TextView
android:id="#+id/sortLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:text="Produkter"
android:singleLine="true"
android:textColor="#color/solid_red"
android:textSize="15dp" />
</LinearLayout>
<Button
android:id="#+id/filterBtn"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="15dp"
android:layout_marginTop="10dp"
android:layout_weight="4"
android:background="#drawable/button_background_red"
android:clickable="true"
android:singleLine="true"
android:text="#string/retailprice"
android:textColor="#color/solid_white"
android:textSize="15dp"
android:textStyle="bold" />
<Spinner
android:id="#+id/sortSpinner"
android:layout_width="0dp"
android:layout_weight="4"
android:layout_height="35dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:background="#drawable/spinner_background"
android:drawSelectorOnTop="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:prompt="#string/sort" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dip"
android:background="#color/divider_color"></LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ListView
android:id="#+id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="#color/divider_color"
android:dividerHeight="1dip"
android:paddingLeft="15dip"
android:scrollbarStyle="outsideInset"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" />
</LinearLayout>
</LinearLayout>
#Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
int marginRemoved = firstVisibleItem * 30;
if (marginRemoved > 110) {
marginRemoved = 110;
}
if (previousMarginRemoved != marginRemoved) {
previousMarginRemoved = marginRemoved;
LinearLayout disappearingHeaderContainer = (LinearLayout) findViewById(R.id.disappearingHeaderLabel);
RelativeLayout.LayoutParams disappearingHeaderContainerLayoutParams = (RelativeLayout.LayoutParams) disappearingHeaderContainer.getLayoutParams();
LinearLayout expandingListViewContainer = (LinearLayout) findViewById(R.id.expandingListContainer);
RelativeLayout.LayoutParams expandingListViewContainerParams = (RelativeLayout.LayoutParams) expandingListViewContainer.getLayoutParams();
if (disappearingHeaderStartMargin == -1 && expandingHeaderStartMargin == -1) {
disappearingHeaderStartMargin = disappearingHeaderContainerLayoutParams.topMargin;
expandingHeaderStartMargin = expandingListViewContainerParams.topMargin;
}
float disappearingHeaderTopMarginFloat = disappearingHeaderStartMargin - (marginRemoved * pixelDensity);
int disappearingHeaderTopMargin = Math.round(disappearingHeaderTopMarginFloat);
if (marginRemoved > 50) {
marginRemoved = 50;
}
float expandingContainerTopMarginFloat = expandingHeaderStartMargin - (marginRemoved * pixelDensity);
int expandingContainerTopMargin = Math.round(expandingContainerTopMarginFloat);
disappearingHeaderContainerLayoutParams.setMargins(disappearingHeaderContainerLayoutParams.leftMargin,
disappearingHeaderTopMargin,
disappearingHeaderContainerLayoutParams.rightMargin,
disappearingHeaderContainerLayoutParams.bottomMargin);
expandingListViewContainerParams.setMargins(expandingListViewContainerParams.leftMargin,
expandingContainerTopMargin,
expandingListViewContainerParams.rightMargin,
expandingListViewContainerParams.bottomMargin);
if ((lastChangeDate < System.currentTimeMillis()-100)) {
lastChangeDate = System.currentTimeMillis();
disappearingHeaderContainer.setLayoutParams(disappearingHeaderContainerLayoutParams);
expandingListViewContainer.setLayoutParams(expandingListViewContainerParams);
}
}
}
};

Categories

Resources