vertical scroll view for dynamically created buttons - android

I am having a problems with adding scroll view in my dynamically created buttons.here is my xml code.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<LinearLayout
android:id="#+id/linear1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="27dp"
android:background="#drawable/custom_border"
android:orientation="vertical" >
<EditText
android:id="#+id/editText1"
android:layout_width="243dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/linearLayout1"
android:layout_marginTop="28dp"
android:ems="10"
android:hint="#string/hinttextitem" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/editText1"
android:layout_alignParentRight="true"
android:layout_marginRight="26dp"
android:background="#drawable/button_shape"
android:onClick="newonClick"
android:text="click" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/linear1"
android:layout_centerHorizontal="true"
android:layout_marginTop="80dp"
android:id="#+id/dynamic"
android:background="#drawable/dynamic_border"
android:orientation="vertical" >
</LinearLayout>
</RelativeLayout>
here is my java code
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void newonClick(View V){
LinearLayout layout=(LinearLayout)findViewById(R.id.linear1);
LinearLayout dynamiclayout=(LinearLayout)findViewById(R.id.dynamic);
dynamiclayout.removeAllViews();
EditText edittext = (EditText) findViewById(R.id.editText1);
int x=Integer.valueOf(edittext.getText().toString());
for(int i=1;i<=x;i++)
{
Button addButton =new Button(this);
addButton.setText("Button"+i);
addButton.setId(i);
dynamiclayout.addView(addButton);
addButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Toast.makeText(getApplicationContext(),
"button is clicked"+v.getId(), 8000).show();
}
});
}
if am adding scroll view in dynamic layout, it will disappear.so how can i add vertical scroll view only for dynamically created buttons.can anyone solve my problem?

try this: place scroll view for LinearLayout only.
<ScrollView
android:layout_width="wrap_content"
android:layout_below="#+id/linear1"
android:layout_height="wrap_content" >
<LinearLayout
android:id="#+id/dynamic"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_marginTop="80dp"
android:background="#drawable/dynamic_border"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>

Try to use,
In XML,
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/linear1"
android:id="#+id/scrollView1">
<LinearLayout
android:id="#+id/dynamic"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_marginTop="80dp"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
In Java:
this.scrollView = (ScrollView) findViewById(R.id.scrollView1);
this.linearLayout = (LinearLayout) findViewById(R.id.dynamic);
this.linearLayout.setOrientation(LinearLayout.VERTICAL);
Button[] btn = new Button[10];
for (int i = 0; i < 10; i++) {
btn[i] = new Button(this);
btn[i].setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
btn[i].setText("This is the button" + i);
this.linearLayout.addView(btn[i]);
}

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/linear1" >
<LinearLayout
android:id="#+id/dynamic"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_marginTop="80dp"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
please replace this code:

Related

Reverse layouts inside RelativeLayout programmatically

I have one relativeLayout and three view's inside RelativeLayout. There views are place on each other.
<RelativeLayout
android:id="#+id/includelayoutgroup"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/transparentColorView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:clickable="true"
android:visibility="visible" />
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/keyboard_main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="visible">
<include
layout="#layout/transfer_keyboard_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/finalRequestView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:clickable="true"
android:visibility="visible">
<include
layout="#layout/fragment_transfer_new_version_container_child"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
</RelativeLayout>
Is it a possible to reverse position my view's? I mean,in my code last Layout is finalRequestView and in button click i would to my last view in first position,and other view's place on my view,
How i can solve this problem?
I try to reverse layout by following demo & it works as you want, please take a look
ReverseLayout.java
public class ReverseLayout extends AppCompatActivity {
LinearLayout llRoot;
Button btReverseLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.reverse_layout);
llRoot = (LinearLayout) findViewById(R.id.llRoot);
btReverseLayout = (Button) findViewById(R.id.btReverseLayout);
btReverseLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
ArrayList<View> alViews = new ArrayList<View>();
for (int i = llRoot.getChildCount() - 1; i >= 0; i--) {
View view = llRoot.getChildAt(i);
llRoot.removeViewAt(i);
alViews.add(view);
}
for (int j = 0; j < alViews.size(); j++) {
llRoot.addView(alViews.get(j));
}
}
});
}
}
reverse_layout.xml layout file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_6"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.tosc185.testproject.Activity6">
<LinearLayout
android:id="#+id/llRoot"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FF0000"
android:gravity="center"
android:orientation="vertical"
android:padding="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:textSize="16dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00FF00"
android:gravity="center"
android:orientation="vertical"
android:padding="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
android:textSize="16dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#0000FF"
android:gravity="center"
android:orientation="vertical"
android:padding="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3"
android:textSize="16dp" />
</LinearLayout>
</LinearLayout>
<Button
android:id="#+id/btReverseLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Reverse Layout" />
</RelativeLayout>

How to shift a LinearLayout when a SlidingDrawer expands?

I am trying to implement a panel in a fragment that can expand on button click from the right side of the screen. I can't use the navigation drawer, because I already have navigation drawers from both left and right sides.
The idea is to achieve something like that:
I was almost able to do it with the SlidingDrawer widget (it's deprecated..), the only problem is that I don't know how to make the LinearLayout to appear in the middle and then to shift when the button to expand the SlidingDrawer is clicked.
I have the following code:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button handle = (Button) findViewById(R.id.handle);
SlidingDrawer drawer = (SlidingDrawer) findViewById(R.id.slidingDrawer);
drawer.setOnDrawerOpenListener(new SlidingDrawer.OnDrawerOpenListener() {
#Override
public void onDrawerOpened() {
}
});
drawer.setOnDrawerCloseListener(new SlidingDrawer.OnDrawerCloseListener() {
#Override
public void onDrawerClosed() {
}
});
}
}
And the XML code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.test.slidingdrawertest.slidingdrawertest.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TEST TEST TEST" />
</LinearLayout>
<LinearLayout
android:layout_alignParentEnd="true"
android:layout_width="wrap_content"
android:layout_height="match_parent">
<SlidingDrawer
android:id="#+id/slidingDrawer"
android:layout_width="200dp"
android:layout_height="400dp"
android:layout_marginTop="100dp"
android:layout_gravity="end"
android:content="#+id/content"
android:handle="#+id/handle"
android:orientation="horizontal">
<Button
android:id="#+id/handle"
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Expand" />
<LinearLayout
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TEST TEST TEST" />
</LinearLayout>
</SlidingDrawer>
</LinearLayout>
</RelativeLayout>
You can edit your XML like this
?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
tools:context="com.test.slidingdrawertest.slidingdrawertest.MainActivity">
<LinearLayout
android:id="#+id/left" // this is your linear layout
android:layout_width="match_parent" // that you want to shift left
android:layout_height="match_parent"
android:layout_toLeftOf="#+id/right" // apply this property due to
android:layout_alignParentLeft="true" //which if the width of sliding menu
android:gravity="center" //increase it will automatically compressed
android:background="#aa00aa"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TEST TEST TEST" />
</LinearLayout>
<LinearLayout
android:id="#+id/right"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:background="#0000aa"
android:layout_height="match_parent">
<SlidingDrawer
android:id="#+id/slidingDrawer"
android:layout_width="200dp" // you can check by increasing or decreasing the with of this slidingdrawer
android:layout_height="400dp"
android:layout_marginTop="100dp"
android:layout_gravity="end"
android:content="#+id/content"
android:handle="#+id/handle"
android:orientation="horizontal">
<Button
android:id="#+id/handle"
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Expand" />
<LinearLayout
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TEST TEST TEST" />
</LinearLayout>
</SlidingDrawer>
</LinearLayout>
</RelativeLayout>
apart from this if set any layout to the right of your linear layout which is initially GONE and as you click on the button its visibility changed to INVISIBLE/VISIBLE so it will shift the linear layout to left. Hope that helps!
If you want a little exemple here is my solution: (I don't know if Avani Nagar's solution works or not):
TextView res;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView img = (TextView)findViewById(R.id.second);
res = (TextView)findViewById(R.id.first);
img.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
img.setX(img.getX() - 5);
changew(img.getX());
}
});
}
private void changew(float w){
res.getLayoutParams().width = (int)(res.getX() +w);
res.requestLayout();
res.invalidate();
}
The xml:
<?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="#android:color/black">
<TextView
android:layout_toRightOf="#+id/first"
android:text="bonjourrrrrr"
android:id="#+id/second"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:background="#android:color/holo_red_dark" />
<TextView
android:text="salutttttttt"
android:id="#id/first"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:background="#android:color/holo_green_light" />
</RelativeLayout>
I managed to do it, it actually wasn't so difficult, but it's a little tricky. Here is the solution:
The xml code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/topLayout"
tools:context="com.test.slidingdrawertest.slidingdrawertest.MainActivity">
<LinearLayout
android:id="#+id/mainLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TEST" />
</LinearLayout>
<LinearLayout
android:layout_alignParentEnd="true"
android:layout_width="wrap_content"
android:layout_height="match_parent">
<SlidingDrawer
android:id="#+id/slidingDrawer"
android:layout_width="200dp"
android:layout_height="400dp"
android:layout_marginTop="100dp"
android:layout_gravity="end"
android:content="#+id/content"
android:handle="#+id/handle"
android:orientation="horizontal">
<Button
android:id="#+id/handle"
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Expand" />
<LinearLayout
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TEST TEST TESTT" />
</LinearLayout>
</SlidingDrawer>
</LinearLayout>
</RelativeLayout>
The code in MainActivity.java:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button handle = (Button) findViewById(R.id.handle);
SlidingDrawer drawer = (SlidingDrawer) findViewById(R.id.slidingDrawer);
final View k = findViewById(R.id.mainLayout);
drawer.setOnDrawerOpenListener(new SlidingDrawer.OnDrawerOpenListener() {
#Override
public void onDrawerOpened() {
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
k.setLayoutParams(params);
}
});
drawer.setOnDrawerCloseListener(new SlidingDrawer.OnDrawerCloseListener() {
#Override
public void onDrawerClosed() {
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
k.setLayoutParams(params);
}
});
}
}
And the explanation: I had to give main main layout an id (in XML) and then find it in the code behind, then I had to apply new parameters to it when the drawer opens or closes. Basically, we need to find the parent layout and set the parameters to it.
Now the LinearLayout is able to shift it's position on drawer open, and it goes back to it's original position on drawer close. Next step is to make this process with an animation, so it's smooth and doesn't just jump back and forth to the new positions.

LinearLayout is null inside button's onClick

I'm trying to hide a linearlayout on a button click and display another linearlayout which is in the same layout file. But the linearlayouts are null inside the onclick of the button.
The displayLayout and editLayout are null.
displayLayout = (LinearLayout) findViewById(R.id.linearLayout);
editLayout = (LinearLayout) findViewById(R.id.editLayout);
edit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
displayLayout = (LinearLayout) findViewById(R.id.linearLayout);
editLayout = (LinearLayout) findViewById(R.id.editLayout);
displayLayout.setVisibility(View.GONE); //error occurs here
editLayout.setVisibility(View.VISIBLE);
}
});
}
Here's the layout file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.prematixsofs.taxiapp.EditUserDetails">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/ScrollView01"
android:layout_width="match_parent"
android:layout_height="fill_parent"
>
<!--Display UserDetails Layout-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/displayLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:padding="15dp">
<TextView
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#drawable/custom_edittext"
android:gravity="center"
android:padding="8dp"
android:paddingLeft="10dp"
android:paddingRight="5dp" />
<TextView
android:id="#+id/phNo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/custom_edittext"
android:gravity="center"
android:padding="8dp"
android:paddingLeft="10dp"
android:paddingRight="5dp" />
<TextView
android:id="#+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/custom_edittext"
android:gravity="center"
android:inputType="textEmailAddress"
android:padding="8dp"
android:paddingLeft="10dp"
android:paddingRight="5dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:padding="15dp">
<Button
android:id="#+id/edit"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:background="#drawable/button_custom"
android:text="Edit"
android:textColor="#ffffff" />
</LinearLayout>
</LinearLayout>
</ScrollView>
<!--Edit Layout -->
<LinearLayout
android:id="#+id/editLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<EditText
android:id="#+id/editName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#drawable/custom_edittext"
android:gravity="center"
android:padding="8dp"
android:paddingLeft="10dp"
android:paddingRight="5dp" />
<EditText
android:id="#+id/editPhNo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/custom_edittext"
android:gravity="center"
android:padding="8dp"
android:paddingLeft="10dp"
android:paddingRight="5dp" />
<EditText
android:id="#+id/editPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/custom_edittext"
android:gravity="center"
android:padding="8dp"
android:paddingLeft="10dp"
android:paddingRight="5dp" />
<EditText
android:id="#+id/editConfirmPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/custom_edittext"
android:gravity="center"
android:padding="8dp"
android:paddingLeft="10dp"
android:paddingRight="5dp" />
</LinearLayout>
Just fix your view ID in your code
displayLayout = (LinearLayout) findViewById(R.id.displayLayout);
editLayout = (LinearLayout) findViewById(R.id.editLayout);
edit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
displayLayout.setVisibility(View.GONE);
editLayout.setVisibility(View.VISIBLE);
}
});
}
error code displayLayout = (LinearLayout) findViewById(R.id.linearLayout);
right code displayLayout = (LinearLayout) findViewById(R.id.displayLayout);
you set a not exist id.

Android: views in container still clickable after container view set to View.GONE

I have a LinearLayout that is a view in a FrameLayout. This LinearLayout sits on top in the frame.
Within this LinearLayout, there are some TextViews that are clickable. When I set the LinearLayout to View.GONE, everything goes away as expected except the TextViews are still clickable.
Why is this? And how do I avoid it other than setting all the clickable TextViews to View.GONE?
XML
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<LinearLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" />
<LinearLayout
android:id="#+id/match_settings_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#40c0a9"
android:visibility="gone"
android:padding="10dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:orientation="horizontal"
android:baselineAligned="false" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:orientation="vertical" >
<com.walintukai.lfdate.CustomFontTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:textSize="20sp"
android:textColor="#fff"
android:text="#string/lbl_age" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:orientation="vertical" >
<com.walintukai.lfdate.CustomFontBoldTextView
android:id="#+id/age_setting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/white_rounded_bg"
android:padding="6dp"
android:textSize="20sp"
android:textColor="#0099cb"
android:text="18 to 99" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:orientation="horizontal"
android:baselineAligned="false" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:orientation="vertical" >
<com.walintukai.lfdate.CustomFontTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:textSize="20sp"
android:textColor="#fff"
android:text="#string/lbl_location" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:orientation="vertical" >
<com.walintukai.lfdate.CustomFontBoldTextView
android:id="#+id/location_setting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/white_rounded_bg"
android:padding="6dp"
android:textSize="20sp"
android:textColor="#0099cb"
android:text="Any Distance" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</FrameLayout>
Activity
// Handles expanding match settings window
final ToggleButton btnShowMatchSettings = (ToggleButton) findViewById(R.id.btn_show_match_settings);
btnShowMatchSettings.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
LinearLayout container = (LinearLayout) findViewById(R.id.match_settings_container);
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
btnShowMatchSettings.setBackgroundResource(R.drawable.ico_menu_open);
container.setAnimation(AnimationUtils.loadAnimation(DashboardActivity.this, R.anim.slide_down));
container.setVisibility(View.VISIBLE);
ageSetting = (CustomFontBoldTextView) findViewById(R.id.age_setting);
ageSetting.setVisibility(View.VISIBLE);
ageSetting.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
new AgePickerDialog().show(getFragmentManager(), "agePicker");
}
});
locationSetting = (CustomFontBoldTextView) findViewById(R.id.location_setting);
locationSetting.setVisibility(View.VISIBLE);
locationSetting.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
new LocationPickerDialog().show(getFragmentManager(), "locationPicker");
}
});
}
else {
btnShowMatchSettings.setBackgroundResource(R.drawable.ico_menu);
container.setAnimation(AnimationUtils.loadAnimation(DashboardActivity.this, R.anim.slide_up));
container.setVisibility(View.GONE);
ageSetting.setVisibility(View.GONE);
locationSetting.setVisibility(View.GONE);
}
}
});
}
The fact that you change the visibility of a view doesn't mean that they are destroyed.
You should try adding something like this
yourButton.setClickable(false) ;

Adding multiple images to horizontal scroll view in android

I am building an application in which I want to add multiple images in a horizontal scrollview and want to scroll these imageson click of two (left and right) srcolling buttons, but I am not able to do that as I am new to android development.So can anybody provide my with the solution how to do it ? Thanks in advance....
put this code in your xml
<HorizontalScrollView
android:id="#+id/xml_full_img_hor_below_view"
android:layout_width="match_parent"
android:layout_height="#dimen/full_img_below_relative_height"
android:layout_alignParentBottom="true"
android:layout_gravity="center"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/xml_full_img_linear_below_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="horizontal" >
</LinearLayout>
</HorizontalScrollView>
/////////////////////////////////////
java code
this model_ProductMaster.listProductImages.size() is images list:
private void setProductImageInView() {
LayoutInflater layoutInflater = (LayoutInflater) viewFullImage
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
linear_below_img_view.removeAllViews();
// Set the image height,widt,scaling and margin of the imageview
for (int i = 0; i < model_ProductMaster.listProductImages.size(); i++) {
convertView = layoutInflater.inflate(
R.layout.xml_row_full_image_view, null, false);
final ImageView img = (ImageView) convertView
.findViewById(R.id.xml_full_img_below_middleimg);
img.setMinimumWidth((int) viewFullImage.getResources()
.getDimension(R.dimen.full_img_below_img_width_height));
img.setMaxWidth((int) viewFullImage.getResources().getDimension(
R.dimen.full_img_below_img_width_height));
img.setMinimumHeight((int) viewFullImage.getResources()
.getDimension(R.dimen.full_img_below_img_width_height));
img.setMaxHeight((int) viewFullImage.getResources().getDimension(
R.dimen.full_img_below_img_width_height));
img.setScaleType(ScaleType.CENTER_INSIDE);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(10, 0, 0, 0);
layoutParams.gravity = Gravity.CENTER;
convertView.setLayoutParams(layoutParams);
img.setScaleType(ScaleType.FIT_XY);
imageLoader.displayImage(
model_ProductMaster.listProductImages.get(i).ImageUrl, img,
options, animateFirstListener);
linear_below_img_view.addView(convertView);
convertView.setId(i);
convertView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
for (int i = 0; i < linear_below_img_view.getChildCount(); i++) {
View view = linear_below_img_view.getChildAt(i);
if (view == v) {
view.setBackgroundResource(R.drawable.xml_popup_border_with_bg);
} else {
view.setBackgroundResource(R.drawable.common_bg_with_dark_border);
}
}
loadImageonCenter(model_ProductMaster.listProductImages
.get(v.getId()).ImageUrl);
System.gc();
}
});
}
linear_below_img_view.getChildAt(0).setBackgroundResource(
R.drawable.xml_popup_border_with_bg);
// Image Starting load
System.gc();
}
main.xml
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="100dp" >
<ImageView
android:id="#+id/xml_home_screen_img_leftarrow"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_centerInParent="true"
android:padding="5dp"
android:src="#drawable/leftarrow" />
<HorizontalScrollView
android:id="#+id/xml_full_img_hor_below_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/xml_full_img_linear_below_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:orientation="horizontal" >
<include
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="#layout/xml_row_full_image_view" />
<include
android:layout_width="wrap_content"
android:layout_height="match_parent"
layout="#layout/xml_row_full_image_view" />
<include
android:layout_width="wrap_content"
android:layout_height="match_parent"
layout="#layout/xml_row_full_image_view" />
<include
android:layout_width="wrap_content"
android:layout_height="match_parent"
layout="#layout/xml_row_full_image_view" />
<include
android:layout_width="wrap_content"
android:layout_height="match_parent"
layout="#layout/xml_row_full_image_view" />
</LinearLayout>
</HorizontalScrollView>
<ImageView
android:id="#+id/xml_home_screen_img_rightarrow"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:padding="5dp"
android:src="#drawable/rightarrow" />
</RelativeLayout>
xml_row_full_image_view.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/xml_full_img_below_mainlinear"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:orientation="horizontal"
android:padding="4dp" >
<ImageView
android:id="#+id/xml_full_img_below_middleimg"
android:layout_width="50dp"
android:layout_height="match_parent"
android:scaleType="fitCenter"
android:src="#drawable/ic_launcher" />
</LinearLayout>

Categories

Resources