How to add info icon on textinputlayout when floating label is raised - android

How to add info icon when floating label is raised just beside hint.
Like this http://prntscr.com/nlipdn
I have tried with below code:
when focus change on edittext.I added info icon.But I don't know how to set info icon beside floating label. I have added but it's not positioning proper.
public void OnFocusChange(View v, bool hasFocus)
{
ImageView _infoView=null;
if (_infoView != null)
{
_songTitleLayout.RemoveView(_infoView);
_infoView = null;
}
if (v==_eSongTitle)
{
if(hasFocus)
{
int length= _songTitleLayout.Hint.Length;
_infoView = new ImageView(this);
_infoView.SetImageResource(Resource.Drawable.MoreInfo);
_songTitleLayout.AddView(_infoView);
}
}
}

Solution:
I add a margin before you add the _inforView by using code below, you can change the values to adjust the margin and size of image:
ViewGroup.MarginLayoutParams paramsw = new ViewGroup.MarginLayoutParams(40,40);
paramsw.SetMargins(200,0,0,0);
CollapsingToolbarLayout.LayoutParams lp = new
CollapsingToolbarLayout.LayoutParams(paramsw);
txtlayoutusername.AddView(_infoView,0,lp);
Here is all the codes I tested:
This is the code in MainActivity:
public class MainActivity : AppCompatActivity
{
TextInputLayout txtlayoutusername;
EditText txtusername;
ImageView _infoView;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.activity_main);
txtlayoutusername = FindViewById<TextInputLayout>(Resource.Id.textuernameInputLayout);
txtusername = FindViewById<EditText>(Resource.Id.txtusername);
txtusername.FocusChange += (object sender, View.FocusChangeEventArgs e) =>
{
if (_infoView != null)
{
txtlayoutusername.RemoveView(_infoView);
_infoView = null;
}
if (sender == txtusername)
{
if (txtusername.IsFocused)
{
int length = txtlayoutusername.Hint.Length;
_infoView = new ImageView(this);
_infoView.SetImageResource(Resource.Drawable.ttt);
ViewGroup.MarginLayoutParams paramsw = new ViewGroup.MarginLayoutParams(40,40);
paramsw.SetMargins(200,0,0,0);
CollapsingToolbarLayout.LayoutParams lp = new CollapsingToolbarLayout.LayoutParams(paramsw);
txtlayoutusername.AddView(_infoView,0,lp);
}
}
};
}
}
Here is code in Xaml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_marginTop="80dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/textuernameInputLayout">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txtusername"
android:hint="User Name"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation = "horizontal"
android:id="#+id/textpasswordInputLayout">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txtpassword"
android:inputType="textPassword"
android:hint="Password"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
The result:

Related

Android textview weird behavior : auto scrolling to top on focus change

I defined a textview with auto-scrolling to bottom enabled and it works.
But when i start the app, the textview content automatically scrolls to the top on the first touch, which appears very strange to me. From then on, it behaves normally, after I scrolls it manually to bottom. I mean, no auto-scrolling to top happens again regardless of the subsequent touchs. And it always scroll to bottom as defined when texts are appended.
How may I identify the cause oh this behavior, in order to circumvent it?.
Here is the the textview layout:
<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:background="#color/colorScreenBackground"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="xxx.xxxxx.xxxx.MainActivity"
tools:showIn="#layout/activity_main"
android:orientation="vertical"
android:weightSum="100">
<TextView
android:id="#+id/result"
android:scrollbars = "vertical"
android:textSize="16sp"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="40"
android:elevation="8dp"
android:textIsSelectable="true"
android:gravity="bottom"
android:background="#color/white"
android:padding="5dp"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Medium" />
<androidx.core.widget.NestedScrollView
android:id="#+id/nested_scroll"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="60"
android:background="#color/gray_background"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp"
tools:listitem="#layout/recyclerview_item"
android:background="#color/gray_background"
/>
</androidx.core.widget.NestedScrollView>
</LinearLayout>
And this is how I use it in code
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
sharedPref = getSharedPreferences(getString(R.string.preference_file_key), Context.MODE_PRIVATE);
setContentView(R.layout.activity_main);
final Runnable r = new Runnable() {
#Override
public void run() {
doubleClick = false;
}
};
final TextView textView = findViewById(R.id.result);
textView.setMovementMethod(new ScrollingMovementMethod());
textView.setTextIsSelectable(true);
textView.setText(deviceLog.getResult());
textView.setOnLongClickListener(this);
recyclerView.setOnDragListener(this);
final NestedScrollView nestedScrollView = findViewById(R.id.nested_scroll);
if (textView.getText().length() == 0) {
LinearLayout.LayoutParams nestedScrolliewLayoutParams = (LinearLayout.LayoutParams) nestedScrollView.getLayoutParams();
nestedScrolliewLayoutParams.weight = 100;
textView.setVisibility(View.GONE);
nestedScrollView.setLayoutParams(nestedScrolliewLayoutParams);
}
textView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (doubleClick) {
LinearLayout.LayoutParams nestedScrolliewLayoutParams = (LinearLayout.LayoutParams) nestedScrollView.getLayoutParams();
LinearLayout.LayoutParams linearLayoutParams = (LinearLayout.LayoutParams) textView.getLayoutParams();
if (textViewEnlarged) {
nestedScrolliewLayoutParams.weight = 60;
linearLayoutParams.weight = 40;
textViewEnlarged = false;
} else {
nestedScrolliewLayoutParams.weight = 20;
linearLayoutParams.weight = 80;
textViewEnlarged = true;
}
nestedScrollView.setLayoutParams(nestedScrolliewLayoutParams);
textView.setLayoutParams(linearLayoutParams);
doubleClick = false;
} else {
doubleClick = true;
Handler doubleClikHandler = new Handler();
doubleClikHandler.postDelayed(r, 500);
}
}
});
}
I have a solution that have done on my Project.
Try to call textView.requestFocus() after set the text value:
itemView.text_view_item_description?.text = "..."
itemView.text_view_item_description?.requestFocus()
Hope It works for you.

Add views vertically in LinearLayout

I'm trying to add views vertically in LinearLayout like the pic below :
the code below gives me something like this :
private void configure(View view) {
LinearLayout palletContainer = view.findViewById(R.id.palette_container);
fillPalletColors(mPalette, palletContainer);
}
private void fillPalletColors(List<Integer> colors, LinearLayout paletteContainer) {
if (getActivity() != null && isAdded()) {
LayoutInflater inflater = getActivity().getLayoutInflater();
for (int color : colors) {
View palletColor = inflater.inflate(R.layout.suggested_color_item_center, paletteContainer, false);
palletColor.setBackgroundColor(color);
paletteContainer.addView(palletColor);
}
}
}
XML :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="vertical">
<LinearLayout
android:id="#+id/palette_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" />
</LinearLayout>

Google vision API Barcode Scanner remove camera view

Currently I am developing a bar code reader android app with Google vision API. I need to start camera preview when button is clicked and until the button is clicked screen should be empty white color screen. When I Try to do this camera preview starts at the same time screen also appears how to solve this problem please help me.
My MainActivity Class
public class MainActivity extends AppCompatActivity implements BarcodeRetriever {
// use a compound button so either checkbox or switch widgets work.
private static final String TAG = "BarcodeMain";
BarcodeCapture barcodeCapture;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
barcodeCapture = (BarcodeCapture) getSupportFragmentManager().findFragmentById(barcode);
barcodeCapture.setRetrieval(this);
findViewById(R.id.refresh).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
barcodeCapture.setShowDrawRect(true)
.setSupportMultipleScan(false)
.setTouchAsCallback(true)
.shouldAutoFocus(true)
.setShowFlash(true)
.setBarcodeFormat(Barcode.ALL_FORMATS)
.setCameraFacing(false ? CameraSource.CAMERA_FACING_FRONT : CameraSource.CAMERA_FACING_BACK)
.setShouldShowText(true);
barcodeCapture.resume();
barcodeCapture.refresh(true);
}
});
}
#Override
public void onRetrieved(final Barcode barcode) {
Log.d(TAG, "Barcode read: " + barcode.displayValue);
runOnUiThread(new Runnable() {
#Override
public void run() {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this)
.setTitle("code retrieved")
.setMessage(barcode.displayValue);
builder.show();
}
});
barcodeCapture.stopScanning();
}
#Override
public void onRetrievedMultiple(final Barcode closetToClick, final List<BarcodeGraphic> barcodeGraphics) {
runOnUiThread(new Runnable() {
#Override
public void run() {
String message = "Code selected : " + closetToClick.displayValue + "\n\nother " +
"codes in frame include : \n";
for (int index = 0; index < barcodeGraphics.size(); index++) {
Barcode barcode = barcodeGraphics.get(index).getBarcode();
message += (index + 1) + ". " + barcode.displayValue + "\n";
}
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this)
.setTitle("code retrieved")
.setMessage(message);
builder.show();
}
});
}
#Override
public void onBitmapScanned(SparseArray<Barcode> sparseArray) {
for (int i = 0; i < sparseArray.size(); i++) {
Barcode barcode = sparseArray.valueAt(i);
Log.e("value", barcode.displayValue);
}
}
#Override
public void onRetrievedFailed(String reason) {
}
#Override
public void onPermissionRequestDenied() {
}
}
My activity_main.xml file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/actions"
android:layout_weight="1"
android:gravity="center">
<fragment
android:id="#+id/barcode"
android:name="com.google.android.gms.samples.vision.barcodereader.BarcodeCapture"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
app:gvb_auto_focus="true"
app:gvb_code_format="code_39|aztec"
app:gvb_flash="false"
app:gvb_rect_colors="#array/rect_color" />
</RelativeLayout>
<LinearLayout
android:id="#+id/actions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:paddingLeft="16dp"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:padding="20dp"
android:paddingRight="16dp">
<RelativeLayout
android:id="#+id/refresh"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:background="#drawable/circle_layout_for_start_scan">
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
I've changed some parts of the xml file: Please try this.
Replace your entire XML with:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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=".MainActivity">
<fragment
android:id="#+id/barcode"
android:name="com.google.android.gms.samples.vision.barcodereader.BarcodeCapture"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginBottom="10dp"
app:gvb_auto_focus="true"
app:gvb_code_format="code_39|aztec"
app:gvb_flash="false"
app:gvb_rect_colors="#array/rect_color"
app:layout_constraintBottom_toTopOf="#+id/button2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<RelativeLayout
android:id="#+id/relative"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#FFFFFF"
app:layout_constraintBottom_toBottomOf="#+id/barcode"
app:layout_constraintTop_toTopOf="#+id/barcode" >
<TextView
android:layout_width="180dp"
android:layout_height="wrap_content"
android:text="Press Start Button To Activate The Scanner"
android:layout_centerInParent="true"
android:textColor="#000000"
android:textStyle="bold"
android:textSize="18sp"
android:gravity="center"/>
</RelativeLayout>
<Button
android:id="#+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginEnd="40dp"
android:layout_marginStart="40dp"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
After changing:
findViewById(R.id.refresh).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
RelativeLayout rel = findViewById(R.id.relative);
rel.setVisibility(View.GONE);
barcodeCapture.setShowDrawRect(true)
.setSupportMultipleScan(false)
.setTouchAsCallback(true)
.shouldAutoFocus(true)
.setShowFlash(true)
.setBarcodeFormat(Barcode.ALL_FORMATS)
.setCameraFacing(false ? CameraSource.CAMERA_FACING_FRONT : CameraSource.CAMERA_FACING_BACK)
.setShouldShowText(true);
barcodeCapture.resume();
barcodeCapture.refresh(true);
}
});
Before the above change, write this:
barcodeCapture.setShowDrawRect(false);
Try it.. and let me know if it works fine
Finally after few days I found a solution for this :)
To do this you have to edit BarcodeCapture.java class which provide by google vision sample. Please edit it like bellow.
add these Two line into onCreate method of BarcodeCapture.java
mPreview.setVisibility(View.GONE);
mGraphicOverlay.setVisibility(View.GONE);
and Comment startCameraSource(); line in the onResume() method of BarcodeCapture.java
finally add these into refresh method in BarcodeCapture.java class
mPreview.setVisibility(View.VISIBLE);
mGraphicOverlay.setVisibility(View.VISIBLE);
startCameraSource();

How to get value from dynamically created edit text in Android?

How to get value from dynamically created EditText in Android?
This is my dynamic view (XML file)
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:id="#+id/et_waypoint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/background"
android:hint="Way Points"
android:padding="10dp"
android:textSize="16sp" />
<Button
android:id="#+id/btn_waypoint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Find" />
</LinearLayout>
And I am using LayoutInflater because I want perfect Designed layout which is not accomplish by me via setLayoutParams so this is the reason I am using LayoutInflater.
And here is my code:
LayoutInflater l = getLayoutInflater();
final LinearLayout mainActivity = (LinearLayout) findViewById(R.id.dynamic);
final View view = l.inflate(R.layout.dynamic_layout_waypoints, null);
buttonWayPoints = (Button) view.findViewById(R.id.btn_waypoint);
editTextWayPoints = (EditText) view.findViewById(R.id.et_waypoint);
mainActivity.addView(editTextWayPoints);
I am new to Android. Most of people suggest this solution but it's not worked for me, the issue is when I implement this code my ADD NEW EDIT TEXT BUTTON not respond me.
This is how I am trying to get inserted value but it returns value of only last created edit text:
public Cursor getPerson(String Query) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor c = db.rawQuery(Query, null);
return c;
}
sb is StringBuilder sb;, w is String w;
String queryWayPoints = "select * from route_table where trip_id = " + t;
Cursor s = myDb.getPerson(queryWayPoints);
int count3 = s.getCount();
for (int j = 0; j < count3; j++) {
s.moveToNext();
w = s.getString(s.getColumnIndex("waypoints"));
// se.append(w + "." + "00");
}
trip_name.setText(n);
trip_date.setText(d);
sb.append(w);
}
trip_route.setText(sb.toString());
Although, I didn't get what exactly your question is, still I'll try to help.
What exactly this code does is, on clicking the button on top an new layout(one that you wanted) will add to the activity screen at runtime, i.e an edittext with a button, and when you click on that button, A toast with the value of respective edittext will be shown. Hence solving the problem of getting the value of dynamically added edittext
MainActivity
public class MainActivity extends AppCompatActivity {
Button generateET;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final LinearLayout myLinearLay = (LinearLayout) findViewById(R.id.dynamic);
generateET = (Button) findViewById(R.id.generateBtn);
generateET.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
LayoutInflater l = getLayoutInflater();
final View viewToAdd = l.inflate(R.layout.to_add, null);
Button buttonWayPoints = (Button) viewToAdd.findViewById(R.id.btn_waypoint);
final EditText editTextWayPoints = (EditText) viewToAdd.findViewById(R.id.et_waypoint);
buttonWayPoints.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (editTextWayPoints.getText().toString() != null) {
Toast.makeText(MainActivity.this, editTextWayPoints.getText().toString(), Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainActivity.this, "No text found", Toast.LENGTH_SHORT).show();
}
}
});
myLinearLay.addView(viewToAdd);
}
});
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.techmahindra.stackques.MainActivity">
<Button
android:id="#+id/generateBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="add editText To layout" />
<ScrollView
android:layout_below="#+id/generateBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<LinearLayout
android:id="#+id/dynamic"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
></LinearLayout>
</ScrollView>
</RelativeLayout>
to_add.xml(layout which will be inflated at runtime)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:id="#+id/et_waypoint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Way Points"
android:padding="10dp"
android:textSize="16sp" />
<Button
android:id="#+id/btn_waypoint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Find" />
</LinearLayout>
There are some problems with your code. You're trying to add editTextWayPoints to mainActivity, but editTextWayPoints already has a parent, which is view. I think you should be adding view to mainActivity (mainActivity.addView(view)). Finally, to access the value of editTextWayPoints, you simply do editTextWayPoints.getText().toString();

Slide up/down layout on click

I am looking to slide/up down a nested layout on its parent layout click.
Ie the parent layout will have a hidden child. On click I would like the parents height to animate down (slide down) to fit the child layout. On click again I would like the child to animate up (slide up). Basically just animating the parents height to show/hide the child.
I have found this which looks to work but seems like a lot of code:
http://gmariotti.blogspot.com/2013/09/expand-and-collapse-animation.html
I have seen a lot of things using 'animateLayoutChanges' to animate things however I cannot get that to work.
I have tried this:
<LinearLayout android:id="#+id/parent"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<LinearLayout android:id="#+id/child"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
android:animateLayoutChanges="true">
<TextView android:id="#+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some text to show/hide"/>
</LinearLayout>
</LinearLayout>
Then in code:
LinearLayout parent = (LinearLayout)findViewById(R.id.parent);
parent.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
LinearLayout child = (LinearLayout)findViewById(R.id.child);
child.setVisibility(child.getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE);
}
});
That sets the visibility of the child view correctly but there is absolutely no animation.
Well, first of all android:animateLayoutChanges effects the child elements. So, obviously, if you are changing the properties of the element itself, it will not be animated.
I think you can accomplish what you are trying to in API 16 by enabling the LayoutTransition.CHANGING animation.
<LinearLayout android:id="#+id/parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:animateLayoutChanges="true">
<TextView android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title"/>
<TextView android:id="#+id/message"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:text="Some text to show/hide"/>
</LinearLayout>
LinearLayout parent = (LinearLayout)findViewById(R.id.parent);
parent.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
View text = findViewById(R.id.text);
text.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
View message = findViewById(R.id.message);
ViewGroup.LayoutParams params = message.getLayoutParams();
params.height = params.height == 0 ? ViewGroup.LayoutParams.WRAP_CONTENT : 0;
message.setLayoutParams(params);
}
});
Try to use SlidingDrawer
use this code
xml layout sideupdown.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="#+id/bopen"
android:layout_width="90sp"
android:layout_height="wrap_content"
android:text="open" />
<Button
android:id="#+id/btogg"
android:layout_width="90sp"
android:layout_height="wrap_content"
android:text="change" />
<Button
android:id="#+id/bclose"
android:layout_width="90sp"
android:layout_height="wrap_content"
android:text="close" />
</LinearLayout>
<SlidingDrawer
android:id="#+id/slidingDrawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:content="#+id/content"
android:handle="#+id/handle" >
<Button
android:id="#+id/handle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Handle" />
<LinearLayout
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<CheckBox
android:id="#+id/chkbok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="On/Off" />
</LinearLayout>
</SlidingDrawer>
</FrameLayout>
java class SlideUpDown.java
public class SlideUpDown extends Activity implements OnClickListener,
OnCheckedChangeListener, OnDrawerOpenListener, OnDrawerCloseListener {
Button opn, cloz, chng, hndl;
CheckBox chkbox;
SlidingDrawer sd;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sideupdown);
refference();
opn.setOnClickListener(this);
cloz.setOnClickListener(this);
chng.setOnClickListener(this);
chkbox.setOnCheckedChangeListener(this);
sd.setOnDrawerOpenListener(this);
sd.setOnDrawerCloseListener(this);
}
private void refference() {
opn = (Button) findViewById(R.id.bopen);
cloz = (Button) findViewById(R.id.bclose);
chng = (Button) findViewById(R.id.btogg);
chkbox = (CheckBox) findViewById(R.id.chkbok);
sd = (SlidingDrawer) findViewById(R.id.slidingDrawer);
hndl = (Button) findViewById(R.id.handle);
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.bopen:
sd.open();
break;
case R.id.bclose:
sd.close();
break;
case R.id.btogg:
sd.toggle();
break;
}
}
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (chkbox.isChecked()) {
sd.lock();
hndl.setEnabled(false);
} else {
sd.unlock();
hndl.setEnabled(true);
}
}
#Override
public void onDrawerOpened() {
}
#Override
public void onDrawerClosed() {
}
#Override
protected void onDestroy() {
super.onDestroy();
}
}
In one of our applications we hide and show a header and footer. We do this by changing the height and visibility of the view.
It looks something like this
ValueAnimator va;
if (show)
va = ValueAnimator.ofInt(0, px);
else
va = ValueAnimator.ofInt(px, 0);
va.setDuration(400);
va.setInterpolator(new DecelerateInterpolator(2));
va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator animation) {
Integer value = (Integer) animation.getAnimatedValue();
topicNavBar.getLayoutParams().height = value;
topicNavBar.requestLayout();
if (value == 0) {
if (show)
topicNavBar.setVisibility(View.VISIBLE);
else
topicNavBar.setVisibility(View.GONE);
}
if (show && value == px) {
animationInProgress = false;
}
if (!show && value == 0) {
animationInProgress = false;
}
}
});
va.start();
Hope this helps

Categories

Resources