How to resize TextView with SeekBar's progress (Android) - android

I'm triying to change the text size of a TextView using a SeekBar, and it's works fine ONLY when i increase the size, when decrease, the "text size" changes well, but the "textview's layout" seems to have the biggest height you put (The text appears in the center of the layout as if has the match_parent property instead of wrap_content).
I tried many combinations of the textview's layout properties (It's in a RelativeLayout)
(H:WRAP_CONT,W:WRAP_CONT / H:MATCH_PAR,W:MATCH_PAR,ALING PARENT TOP TRUE /.....)
Can someone help me??
EDIT: The textview should appear on top
LAYOUT
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/preview_preview"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/preview_image"
android:layout_width="match_parent"
android:layout_height="match_parent" android:background="#drawable/cuadros_001"/>
<TextView
android:id="#+id/preview_text_top"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="TextView"
android:textColor="#FFFFFF"/>
<TextView
android:id="#+id/preview_text_bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="2.5dp"
android:gravity="bottom|center"
android:text="PREVIEW_TEXT_BOTTOM"
android:textColor="#FFFFFF"
android:textSize="25dp" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true"/>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<GridView
android:id="#+id/preview_gridview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/backgroundtransparencia"
android:gravity="center"
android:horizontalSpacing="5dp"
android:numColumns="3"
android:stretchMode="columnWidth"
android:verticalSpacing="10dp" >
</GridView>
</LinearLayout>
<LinearLayout
android:id="#+id/preview_child_2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
</ViewFlipper>
---SEEKBAR--
seekbar_toptext =(SeekBar)findViewById(R.id.seekbar_toptext);
seekbar_toptext.setProgress(40);
seekbar_toptext.incrementProgressBy(05);
seekbar_toptext.setMax(100);
seekbar_toptext.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
int topsize;
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
preview_text_top.setTextSize(TypedValue.COMPLEX_UNIT_SP ,progress);
}
});
Thanks in advance.

Try this Code...
I hope this will helps to you...
final TextView t1=new TextView(this);
t1.setText("Hello Android");
final SeekBar sk=(SeekBar) findViewById(R.id.seekBar1);
sk.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
#Override
public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {
// TODO Auto-generated method stub
t1.setTextSize(progress);
Toast.makeText(getApplicationContext(), String.valueOf(progress),Toast.LENGTH_LONG).show();
}
});

Related

Drawable gets changed if clicked twice on edit text

I have two edit text views on which I have added two drawables. One is edit_text_bottom_line and another is edit_drawable.
Now I want to show edit_text_bottom_line drawable onClick of an edit text input.So I can see the layout like this :
This worked. Now Again I want to show another drawable when the we again click on edit text input and floating hint appears that time it should look like this:
This also works. But now if I again click on edit text view then it changes the layout edit_text_bottom_line drawable appears like this:
I want to show blue drawable when user starts typing and till he is on that edit text view and after if edit text is focused.
How can I find out if edit text is focused? I tried from onFocusChangeListener if the edit text is focused show the blue drawable but it gets dispappear on next click.
Layout:
<?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"
android:background="#drawable/bg"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.kiranacustomerapp.Activities.SearchActivity"
tools:showIn="#layout/activity_search">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="380dp"
android:background="#android:color/white"
android:orientation="vertical"
android:id="#+id/linearLayoutContainer">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/linearp">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_height="wrap_content"
android:id="#+id/linear1"
android:layout_marginTop="10dp">
<android.support.design.widget.TextInputLayout
android:id="#+id/input_layout_item_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="#drawable/bg"
android:id="#+id/linearLayoutSpinner"
android:visibility="gone">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:id="#+id/recyclerview"
android:layout_margin="08dp"></android.support.v7.widget.RecyclerView>
</LinearLayout>
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="40dp"
android:id="#+id/editTextItemName"
android:layout_gravity="center_horizontal|center_vertical"
android:hint="#string/item_name"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="07dp"
android:textSize="14sp"
android:imeOptions="actionDone"
android:background="#drawable/edit_text_bottom_line"
android:textStyle="bold"
android:inputType="text"
android:textColor="#color/lighttextcolor">
</android.support.design.widget.TextInputEditText>
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linear2"
android:layout_below="#+id/linear1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<android.support.design.widget.TextInputLayout
android:id="#+id/input_layout_item_unit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="#drawable/bg"
android:id="#+id/linearLayoutUnits"
android:visibility="gone">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:id="#+id/recyclerviewUnits"
android:layout_margin="08dp"></android.support.v7.widget.RecyclerView>
</LinearLayout>
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="40dp"
android:focusable="false"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="07dp"
android:id="#+id/editTextItemUnit"
android:layout_gravity="center_horizontal"
android:hint="#string/unit"
android:textSize="14sp"
android:textStyle="bold"
android:imeOptions="actionDone"
android:background="#drawable/edit_text_bottom_line"
android:inputType="text"
android:textColor="#color/lighttextcolor" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linear3"
android:layout_below="#+id/linear2">
<android.support.design.widget.TextInputLayout
android:id="#+id/input_layout_item_quantity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="02dp">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="05dp"
android:id="#+id/editTextItemQuantity"
android:layout_gravity="center_horizontal"
android:hint="#string/quantity"
android:textSize="14sp"
android:imeOptions="actionDone"
android:textColorHint="#color/grey"
android:textStyle="bold"
android:background="#drawable/edit_text_bottom_line"
android:inputType="number"
android:textColor="#color/lighttextcolor" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="false"
android:layout_centerHorizontal="true"
android:layout_below="#+id/linearp"
android:layout_marginTop="130dp">
<Button
android:layout_width="100dp"
android:layout_height="30dp"
android:text="Select"
style="?android:attr/borderlessButtonStyle"
android:id="#+id/buttonSelect"
android:background="#drawable/btn_hlf_blue"
android:textColor="#android:color/white"
android:textSize="12sp"
android:layout_alignParentBottom="false"
android:layout_centerHorizontal="true" />
</RelativeLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
code:
containerLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
edt_Item_Name.setFocusable(false);
edt_Item_Unit.setFocusable(false);
edt_Item_quantity.setFocusable(false);
linearLayoutRecycleView.setVisibility(View.GONE);
linearLayoutUnits.setVisibility(View.GONE);
textInput_Item_quantity.setVisibility(View.VISIBLE);
textInput_Item_Unit.setVisibility(View.VISIBLE);
textInput_Item_Unit.setBackgroundResource(0);
textInput_Item_name.setBackgroundResource(0);
edt_Item_Name.setBackgroundDrawable(ContextCompat.getDrawable(SearchActivity.this,R.drawable.edit_text_bottom_line));
edt_Item_Unit.setBackgroundDrawable(ContextCompat.getDrawable(SearchActivity.this,R.drawable.edit_text_bottom_line));
edt_Item_quantity.setBackgroundDrawable(ContextCompat.getDrawable(SearchActivity.this,R.drawable.edit_text_bottom_line));
edt_Item_Name.setText("");
edt_Item_quantity.setText("");
edt_Item_Unit.setText("");
}
});
edt_Item_Name.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View view, boolean b) {
if(b) {
edt_Item_Name.setBackgroundDrawable(ContextCompat.getDrawable(SearchActivity.this, R.drawable.edit_drawable));
edt_Item_Unit.setBackgroundDrawable(ContextCompat.getDrawable(SearchActivity.this, R.drawable.edit_text_bottom_line));
edt_Item_quantity.setBackgroundDrawable(ContextCompat.getDrawable(SearchActivity.this, R.drawable.edit_text_bottom_line));
}
}
});
edt_Item_Unit.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View view, boolean b) {
if(b) {
edt_Item_Unit.setBackgroundDrawable(ContextCompat.getDrawable(SearchActivity.this, R.drawable.edit_drawable));
edt_Item_Name.setBackgroundDrawable(ContextCompat.getDrawable(SearchActivity.this, R.drawable.edit_text_bottom_line));
edt_Item_quantity.setBackgroundDrawable(ContextCompat.getDrawable(SearchActivity.this, R.drawable.edit_text_bottom_line));
}
}
});
edt_Item_quantity.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View view, boolean b) {
edt_Item_quantity.setBackgroundDrawable(ContextCompat.getDrawable(SearchActivity.this,R.drawable.edit_drawable));
edt_Item_Name.setBackgroundDrawable(ContextCompat.getDrawable(SearchActivity.this,R.drawable.edit_text_bottom_line));
edt_Item_Unit.setBackgroundDrawable(ContextCompat.getDrawable(SearchActivity.this,R.drawable.edit_text_bottom_line));
}
});
edt_Item_Name.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
edt_Item_Name.setFocusableInTouchMode(true);
mRecyclerView.setLayoutManager(new LinearLayoutManager(SearchActivity.this));
mRecyclerView.setAdapter(mAdapter);
edt_Item_Name.setText("");
edt_Item_Name.setBackgroundResource(R.drawable.edit_text_bottom_line);
edt_Item_quantity.setBackgroundDrawable(ContextCompat.getDrawable(SearchActivity.this,R.drawable.edit_text_bottom_line));
edt_Item_Unit.setBackgroundDrawable(ContextCompat.getDrawable(SearchActivity.this,R.drawable.edit_text_bottom_line));
edt_Item_Name.setHintTextColor(ContextCompat.getColor(SearchActivity.this,R.color.grey));
linearLayoutRecycleView.setVisibility(View.VISIBLE);
linearLayoutUnits.setVisibility(View.GONE);
textInput_Item_quantity.setVisibility(View.GONE);
textInput_Item_Unit.setVisibility(View.GONE);
textInput_Item_name.setBackgroundResource(R.drawable.purple_bg);
textInput_Item_Unit.setBackgroundResource(0);
}
});
edt_Item_Name.addTextChangedListener(new TextWatcher() {
#Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
// When user changed the Text
SearchActivity.this.mAdapter.getFilter().filter(cs);
}
#Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
#Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
}
});
edt_Item_Unit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
edt_Item_Unit.setFocusable(true);
edt_Item_Name.setFocusable(false);
edt_Item_Unit.setFocusableInTouchMode(true);
edt_Item_Name.setBackgroundResource(0);
mUnitsRecyclerView.setLayoutManager(new LinearLayoutManager(SearchActivity.this));
mUnitsRecyclerView.setAdapter(mUnitsAdapter);
edt_Item_Unit.setText("");
edt_Item_Unit.setBackgroundResource(R.drawable.edit_text_bottom_line);
edt_Item_Unit.setHintTextColor(ContextCompat.getColor(SearchActivity.this,R.color.grey));
edt_Item_Name.setBackgroundDrawable(ContextCompat.getDrawable(SearchActivity.this,R.drawable.edit_text_bottom_line));
edt_Item_quantity.setBackgroundDrawable(ContextCompat.getDrawable(SearchActivity.this,R.drawable.edit_text_bottom_line));
linearLayoutUnits.setVisibility(View.VISIBLE);
linearLayoutRecycleView.setVisibility(View.GONE);
textInput_Item_quantity.setVisibility(View.GONE);
textInput_Item_Unit.setBackgroundResource(R.drawable.purple_bg);
}
});
edt_Item_Unit.addTextChangedListener(new TextWatcher() {
#Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
// When user changed the Text
SearchActivity.this.mUnitsAdapter.getFilter().filter(cs);
}
#Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
#Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
}
});
edt_Item_quantity.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
edt_Item_quantity.setFocusableInTouchMode(true);
edt_Item_Name.setBackgroundDrawable(ContextCompat.getDrawable(SearchActivity.this,R.drawable.edit_text_bottom_line));
edt_Item_Unit.setBackgroundDrawable(ContextCompat.getDrawable(SearchActivity.this,R.drawable.edit_text_bottom_line));
}
});
edt_Item_quantity.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View view, boolean b) {
if(b) {
edt_Item_Name.setBackgroundDrawable(ContextCompat.getDrawable(SearchActivity.this, R.drawable.edit_text_bottom_line));
edt_Item_Unit.setBackgroundDrawable(ContextCompat.getDrawable(SearchActivity.this, R.drawable.edit_text_bottom_line));
edt_Item_quantity.setBackgroundDrawable(ContextCompat.getDrawable(SearchActivity.this, R.drawable.edit_drawable));
}
else {
}
}
});
Or rather applying two layouts, I have set the accent color as blue in the theme so by default the edit text takes blue color if focused that's fine but when I change the drawable of grey line after that how can I go to default blue line of an edit text?
Please help, thank you..
Just do one thing make your input text layout like this:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hintTextAppearance="#android:style/TextAppearance.Small">
<EditText
android:id="#+id/user_name"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:padding="#dimen/_10sdp"
android:hint="#string/full_name"
android:inputType="text"
android:background="#android:color/transparent"
/>
</android.support.design.widget.TextInputLayout>
And it will solve your problem.
Change your xml TextInputLayout and TextInputEditText with this:
<android.support.design.widget.TextInputLayout
android:id="#+id/input_layout_item_quantity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="02dp"
android:textColorHint="#color/grey">
<android.support.design.widget.TextInputEditText
android:id="#+id/editTextItemQuantity"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="05dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:hint="#string/quantity"
android:imeOptions="actionDone"
android:inputType="number"
android:textColor="#color/lighttextcolor"
android:textSize="14sp"
android:textStyle="bold"
android:theme="#style/style_edittext_color_control"/>
</android.support.design.widget.TextInputLayout>
In your res/values/styles.xml add this:
<style name="style_edittext_color_control" parent="Theme.AppCompat.Light">
<item name="colorControlNormal">#color/grey</item>
<item name="colorControlActivated">#color/blue</item>
</style>
Hope this will give you proper result.

displaying of email edit text field with buttons submit and cancel on clicking forgot password button

I am new to android and I am making a app where i need to display a email edit text field with 2 buttons submit and cancel when i click forgot password button and it should display below it. Could anyone please help me with the xml layout info and java as well. Help appreciated and thanks in advance.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:id="#+id/LoginLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:gravity="center_horizontal"
android:orientation="vertical" >
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_alignLeft="#+id/editText1"
android:layout_below="#+id/editText1"
android:layout_marginTop="21dp"
android:background="#drawable/rounders_fpass"
android:ems="10"
android:hint="PASSWORD"
android:inputType="textPassword"
android:paddingLeft="10dp" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="41dp"
android:background="#drawable/rounders_email"
android:ems="10"
android:hint="EMAIL ID"
android:inputType="textEmailAddress"
android:paddingLeft="10dp" />
<Button
android:id="#+id/button_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/editText2"
android:layout_marginTop="25dp"
android:gravity="center"
android:text="LOGIN" />
<Button
android:id="#+id/fp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Forgot Password?" />
<TextView
android:id="#+id/appear"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_below="#+id/fp"
android:layout_centerHorizontal="true"
android:layout_marginTop="36dp"
android:text="APPEAR" />
</RelativeLayout>
</RelativeLayout>
JAVA:
public class Login extends Activity {
Button log, fp;
TextView forgot;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
// views
views();
// clicklistener
setClickListenerOnButton_log();
setClickListenerOnButton_fp();
}
private void setClickListenerOnButton_fp() {
// TODO Auto-generated method stub
fp.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
setContentView(forgot);
forgot.setVisibility(View.VISIBLE);
}
});
}
private void views() {
// TODO Auto-generated method stub
log = (Button) findViewById(R.id.button_login);
fp = (Button) findViewById(R.id.fp);
forgot = (TextView) findViewById(R.id.appear);
}
private void setClickListenerOnButton_log() {
// TODO Auto-generated method stub
log.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent(Login.this, MainActivity.class));
}
});
}
}
Try this
Just Remove
"setContentView(forgot);" Line
from your setClickListenerOnButton_fp().
And run your App. Your App will not crash.
Try and let me know, is this resolves your issue.

Android allow multi-touch on an activity

I am trying to allow the user to put a ring on the circle on the screen and then press the larger button so that the circle goes to the next ring size.
Everything work fines when no ring is on the screen.
However when a ring it on the screen no other touches are called and the buttons and the seekbar does not work.
I'm new in android and i haven't came across this requirement before. Is there a way I can allow multi-touch gestures on the activity or a way to ignore touches on that specific layout?
XML File
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/White"
android:splitMotionEvents="false"
>
<TextView
android:id="#+id/us"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/uslbl"
android:padding="#dimen/standard_margin"
android:text="size"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/pressed_gemporia" />
<TextView
android:id="#+id/uklbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/uslbl"
android:padding="#dimen/standard_margin"
android:text="UK Size:"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/Black" />
<TextView
android:id="#+id/uk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/uklbl"
android:layout_alignBottom="#+id/uklbl"
android:layout_toRightOf="#+id/uklbl"
android:padding="#dimen/standard_margin"
android:text="size"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/pressed_gemporia" />
<ImageView
android:id="#+id/ci"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
<TextView
android:id="#+id/uslbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/uk"
android:gravity="left"
android:padding="#dimen/standard_margin"
android:text="US Size:"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/Black" />
<SeekBar
android:id="#+id/seekbar"
android:progressDrawable="#drawable/red_scrubber_progress"
android:thumb="#drawable/red_scrubber_control"
android:max="8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/divider" />
<View
android:id="#+id/divider"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/uklbl"
android:layout_marginTop="18dp"
android:background="#color/pressed_gemporia" />
<TextView
android:id="#+id/sizes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:padding="#dimen/standard_margin"
android:layout_below="#+id/seekbar"
android:text="TextView" android:textColor="#color/pressed_gemporia" />
<Button
android:id="#+id/right"
android:layout_width="100dp"
android:textColor="#color/pressed_gemporia"
android:layout_height="wrap_content"
android:background="#color/White"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/left"
android:text="Larger" />
<Button
android:id="#+id/left"
android:layout_width="100dp"
android:background="#color/White"
android:textColor="#color/pressed_gemporia"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="Smaller" />
<ImageView
android:id="#+id/ring"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/ci"
android:layout_centerHorizontal="true"
android:src="#drawable/j" />
Java Code
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ring_sizes);
left = (Button)findViewById(R.id.left);
right = (Button)findViewById(R.id.right);
us = (TextView) findViewById(R.id.us);
uk = (TextView) findViewById(R.id.uk);
ci = (ImageView)findViewById(R.id.ci);
ring = (ImageView)findViewById(R.id.ring);
sizes.add(R.drawable.j);
sizes.add(R.drawable.l);
sizes.add(R.drawable.n);
sizes.add(R.drawable.p);
sizes.add(R.drawable.r);
sizes.add(R.drawable.t);
sizes.add(R.drawable.v);
sizes.add(R.drawable.x);
sizes.add(R.drawable.z);
USsizes.add("5");
USsizes.add("6");
USsizes.add("7");
USsizes.add("8");
USsizes.add("9");
USsizes.add("10");
USsizes.add("11");
USsizes.add("12");
USsizes.add("13");
UKsizes.add("J-K");
UKsizes.add("L-M");
UKsizes.add("N-O");
UKsizes.add("P-Q");
UKsizes.add("R-S");
UKsizes.add("T-U");
UKsizes.add("V-W");
UKsizes.add("X-Y");
UKsizes.add("Z+");
color = (getBaseContext().getResources().getColor(R.color.pressed_gemporia));
value = (TextView) findViewById(R.id.sizes);
seekbar = (SeekBar) findViewById(R.id.seekbar);
seekbar.getProgressDrawable().setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
value.setText("UK Size : "+UKsizes.get(0) + " - US Size: " + USsizes.get(0));
setUpViews();
seekbar.setOnSeekBarChangeListener( new OnSeekBarChangeListener()
{
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser)
{
ring.setImageResource(sizes.get(progress));
us.setText(USsizes.get(progress));
uk.setText(UKsizes.get(progress));
counter=progress;
value.setText("UK Size : "+UKsizes.get(progress) + " - US Size: " + USsizes.get(progress));
}
public void onStartTrackingTouch(SeekBar seekBar)
{
// TODO Auto-generated method stub
}
public void onStopTrackingTouch(SeekBar seekBar)
{
// TODO Auto-generated method stub
}
});
}
public void setUpViews(){
ring.setImageResource(sizes.get(counter));
us.setText(USsizes.get(counter));
uk.setText(UKsizes.get(counter));
right.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View view)
{
if(UKsizes.size()>counter+1){
ring.setImageResource(sizes.get(counter+1));
seekbar.setProgress(counter+1);
}
}
});
left.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View view)
{
if(counter!=0){
ring.setImageResource(sizes.get(counter));
seekbar.setProgress(counter-1);
} }
});
}
}
There is a way to ignore touches in particular layout,for that you should add
android:splitMotionEvents="false"
in your layout . You can refer answers from thie following link
https://stackoverflow.com/questions/12777435/disable-multi-finger-touch-in-my-app

I want to set minumum value in my seekbar android

I want my seekbar having values from 33 to 80, I have read in Google, that we cannot set minimum in xml, so I add 33 to progress. But the thing is that my seekbar gets values from 33 to 113(max + 30). Any tips will be valuable for me, thank you.
TextView textView123;
SeekBar seekBar;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_calc);
seekBar = (SeekBar) findViewById(R.id.seekBar1);
textView123 = (TextView) findViewById(R.id.progress);
textView123.setText(seekBar.getProgress() + " ");
seekBar.setOnSeekBarChangeListener(
new OnSeekBarChangeListener() {
int progress = 0;
#Override
public void onProgressChanged(SeekBar seekBar,
int progresValue, boolean fromUser) {
progress = progresValue + 33;
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
// Do something here,
}
#Override
public void onStopTrackingTouch(SeekBar arg0) {
// TODO Auto-generated method stub
textView123.setText(progress + " ");
}
});
xml layout
<ImageView
android:id="#+id/background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="center"
android:src="#drawable/backgroundpic" />
<TextView
android:id="#+id/textView4"
android:layout_width="match_parent"
android:layout_height="240dp"
android:layout_alignParentLeft="true"
android:layout_marginTop="20dp"
android:background="#color/white" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/seekBar1"
android:layout_alignParentLeft="true"
android:layout_marginLeft="14dp"
android:text="Quantity"
android:textAppearance="?android:attr/textAppearanceLarge" />
<SeekBar
android:id="#+id/seekBar1"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/textView4"
android:layout_marginTop="27dp"
android:max="80"
android:progress="1" />
<TextView
android:id="#+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/textView1"
android:layout_alignParentRight="true"
android:layout_marginRight="91dp"
android:text="33"
android:textAppearance="?android:attr/textAppearanceSmall" />
</RelativeLayout>
Simple solution:
Set max to the actual value you want minus the min value you programmatically add in onProgressChanged.
In your case, simply set max to 47 (80 - 33).

How to align a View's top to another View's vertical center?

I need to align View2 top-left corner to View1's center, but I cannot figure out how to do it.
Here is how to do it!
Make an xml like
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:background="#FFFF99" >
<LinearLayout
android:id="#+id/view1"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_margin="10dp"
android:background="#440000"
android:orientation="horizontal" >
</LinearLayout>
<LinearLayout
android:id="#+id/container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#id/view1"
android:layout_alignTop="#id/view1"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/view2"
android:layout_width="200dp"
android:layout_height="100dp"
android:background="#99004400"
android:orientation="horizontal" >
</LinearLayout>
</LinearLayout>
</RelativeLayout>
In your activty
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public void onWindowFocusChanged(boolean hasFocus) {
// TODO Auto-generated method stub
super.onWindowFocusChanged(hasFocus);
LinearLayout v1=(LinearLayout)findViewById(R.id.view1);
LinearLayout v2=(LinearLayout)findViewById(R.id.view2);
LinearLayout container=(LinearLayout)findViewById(R.id.container);
int heightV1=v1.getHeight();
int widthV1=v1.getWidth();
container.setPadding(widthV1/2, heightV1/2, 0, 0);
}
Gives output like
try this
RelativeLayout.LayoutParams gpsViewLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT );
gpsViewLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
gpsViewLayoutParams.addRule(RelativeLayout.ALIGN_RIGHT);
this.relativeLayout.addView(gpsView,gpsViewLayoutParams);
Is this of any help to you?
<RelativeLayout>
<View1 />
<View2
Layout_marginTop= (view1Height/2)+view1margin
Layout_marginLeft=(view1Width/2)+view1margin />
</RelativeLayout>

Categories

Resources