I have an activity in which I have inflated another layout. OnClick of next destination I am getting inflated a new layout. Now I want to remove the inflated layout. So I want to access the linear layout of remove from inside inflated layout. How can I access this??
Layout looks like this :
I have achieved to inflate layout and remove the first destination from parent which is a part of parent layout. Now I want to do same with inflated destination layout. onClick of remove the inflated layout should get removed.
Next_destination layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_weight="1.00"
android:background="#android:color/white"
android:id="#+id/LinearAddedDestination">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="DESTINATION"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="40dp"
android:orientation="horizontal"
android:background="#drawable/shape"
android:gravity="right"
android:layout_gravity="center|right"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="80dp"
android:id="#+id/remove">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_clear_black_18dp"
android:layout_marginLeft="05dp"
android:layout_marginTop="05dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="REMOVE"
android:layout_gravity="center"
android:layout_marginLeft="05dp"
android:textSize="14sp"
android:layout_marginRight="15dp" />
</LinearLayout>
</LinearLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="08dp"
android:background="#drawable/line2"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginStart="20dp"
android:background="#drawable/ic_place_black_48dp"
android:layout_marginTop="05dp"
android:layout_gravity="center" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableEnd="#drawable/ic_chevron_right_black_24dp"
android:layout_marginEnd="10dp"
android:text="#string/Loc"
android:layout_gravity="center"
android:layout_marginTop="05dp"
android:textAppearance="#android:style/TextAppearance.Medium"
android:cursorVisible="false"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Street/Building/Place"
android:layout_marginStart="48dp"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginStart="20dp"
android:background="#drawable/ic_description_black_48dp"
android:layout_marginTop="10dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginEnd="10dp"
android:hint="#string/LocationDetails"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_marginStart="48dp"
android:hint="#string/HouseDetails" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginStart="20dp"
android:background="#drawable/ic_person_black_48dp"
android:layout_marginTop="05dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:text="#string/additionalContact"
android:textAppearance="?android:attr/textAppearanceMedium"
android:drawableEnd="#drawable/ic_expand_more_black_24dp"
android:layout_marginTop="08dp"
android:layout_marginStart="05dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="60dp"
android:layout_marginEnd="50dp"
android:layout_gravity="center"
android:visibility="gone"
android:layout_marginTop="20dp">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Name"
android:layout_gravity="center"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Phone"
android:layout_gravity="center"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/or"
android:layout_gravity="center"
android:layout_marginTop="20dp" />
<LinearLayout
android:layout_width="220dp"
android:layout_height="40dp"
android:background="#drawable/shape"
android:layout_gravity="center_horizontal">
<ImageButton
android:layout_width="20dp"
android:layout_height="20dp"
android:background="#drawable/phone2"
android:layout_gravity="center"
android:layout_marginStart="30dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/addFromContacts"
android:layout_gravity="center"
android:layout_marginStart="20dp" />
</LinearLayout>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_marginLeft="48dp"
android:hint="#string/contact1"
android:layout_marginTop="10dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:focusable="true"
android:focusableInTouchMode="true">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginStart="20dp"
android:background="#drawable/ic_description_black_48dp"
android:layout_marginTop="10dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginEnd="10dp"
android:hint="Instruction"
android:layout_gravity="center"
android:layout_marginLeft="10dp" />
</LinearLayout>
</LinearLayout>
Activity from on which the layout is inflated.
View newDestination;
ViewGroup parent;
nextDestination.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
removeDestination.setVisibility(View.VISIBLE);
newDestination = getLayoutInflater().inflate(
R.layout.next_destination_layout, addDestination, true);
}
});
removeDestination.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
parent = (ViewGroup)destination.getParent();
parent.removeView(destination);
}
});
How to achieve this?? Please help...
{ ll.removeView(view)// to remove particular view
ll.removeViewAt(position);// to remove view from particular position
}
Related
when I press the save button does not work after pressing it several time button is working sometimes first-time press is working sometimes after pressing moreover 10 times button is not working.Also i have toast messege to determine it is working or not the toast messege appear after pressing several time to the button.
binding.savebtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(Settringsactivity.this,"ok",Toast.LENGTH_LONG).show();
String status=binding.etStatus.getText().toString();
String username=binding.etUsername.getText().toString();
HashMap<String, Object> obj=new HashMap<>();
Toast.makeText(Settringsactivity.this,username,Toast.LENGTH_LONG).show();
obj.put("username",username);
obj.put("about",status);
if(name!=null) {
Toast.makeText(Settringsactivity.this,"Updated",Toast.LENGTH_LONG).show();
database.getReference().child("Users").child(name).updateChildren(obj);
}
}
});
Here is the xml code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/savebtn"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:background="#color/white"
android:foregroundTint="#B11B1B"
tools:context=".Settringsactivity">
<ImageView
android:id="#+id/settingsbackarraow"
android:layout_width="30dp"
android:layout_height="30dp"
android:backgroundTint="#FFFFFF"
app:srcCompat="#android:drawable/checkbox_on_background" />
<LinearLayout
android:id="#+id/flinear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/settingsbackarraow"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:gravity="center"
android:orientation="vertical">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/profileimage"
android:layout_width="120dp"
android:layout_height="120dp"
android:backgroundTint="#FFFFFF"
app:civ_border_color="#FF000000"
app:civ_border_width="2dp"
android:src="#drawable/img" />
<ImageView
android:id="#+id/plus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="#android:drawable/btn_plus" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Username"
android:textColor="#100606" />
<EditText
android:id="#+id/etUsername"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:textColor="#color/black"
android:hint="Enter your name"
android:inputType="textPersonName" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Username"
android:textColor="#100606" />
<EditText
android:id="#+id/etStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="About"
android:textColor="#color/black"
android:inputType="textPersonName" />
</LinearLayout>
<Button
android:layout_width="100dp"
android:layout_height="50dp"
android:elevation="15sp"
android:background="#1966FB"
android:layout_gravity="right"
android:text="Save" />
</LinearLayout>
</RelativeLayout>
I have cards in a horizontal LinearLayout which is then in a HorizontalScrollView that I would like to rotate about left to right and back like an image slideshow.
Here is my XML, it contains 5 cards which are in horizontal alignment
<HorizontalScrollView
android:id="#+id/horizontal_scroller"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:scrollbars="none">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<androidx.cardview.widget.CardView
android:layout_width="180dp"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
app:cardCornerRadius="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="8dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_margin="10dp"
android:background="#drawable/testimage" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="5dp"
android:gravity="end"
android:text="USD 300"
android:textAlignment="viewEnd"
android:textColor="#ce375e"
android:textSize="15dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="9dp"
android:layout_marginBottom="8dp"
android:text="Product 1"
android:textSize="14sp" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="180dp"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
app:cardCornerRadius="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="8dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_margin="10dp"
android:background="#drawable/testimage" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="5dp"
android:gravity="end"
android:text="USD 300"
android:textAlignment="viewEnd"
android:textColor="#ce375e"
android:textSize="15dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="9dp"
android:layout_marginBottom="8dp"
android:text="Product 2"
android:textSize="14sp" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="180dp"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
app:cardCornerRadius="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="8dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_margin="10dp"
android:background="#drawable/testimage" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="5dp"
android:gravity="end"
android:text="USD 300"
android:textAlignment="viewEnd"
android:textColor="#ce375e"
android:textSize="15dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="9dp"
android:layout_marginBottom="8dp"
android:text="Product 3"
android:textSize="14sp" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="180dp"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
app:cardCornerRadius="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="8dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_margin="10dp"
android:background="#drawable/testimage" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="5dp"
android:gravity="end"
android:text="USD 300"
android:textAlignment="viewEnd"
android:textColor="#ce375e"
android:textSize="15dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="9dp"
android:layout_marginBottom="8dp"
android:text="Product 4"
android:textSize="14sp" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="180dp"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
app:cardCornerRadius="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="8dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_margin="10dp"
android:background="#drawable/testimage" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="5dp"
android:gravity="end"
android:text="USD 300"
android:textAlignment="viewEnd"
android:textColor="#ce375e"
android:textSize="15dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="9dp"
android:layout_marginBottom="8dp"
android:text="Product 5"
android:textSize="14sp" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
</HorizontalScrollView>
I have tried using tags such as <ViewFlipper with that users cannot scroll themselves within the layout.
Use a timer for continuous scrolling, and using canScrollHorizontally() to check wether it reached the furthest right then start scrolling left,
canScrollHorizontally() takes positive int for right direction, negative int for left direction
private HorizontalScrollView scrollView;
private boolean scrollingLeft;
int pace = 50;
private Timer timer;
timer = new Timer("horizontalScrollViewTimer");
timer.scheduleAtFixedRate(new TimerTask() {
#Override
public void run() {
runOnUiThread(new Runnable() {
#Override
public void run() {
if (scrollView.canScrollHorizontally(1)&&!scrollingLeft ) {
Log.d(TAG, "Scrolling right");
scrollView.smoothScrollBy(pace, 0);
}
else {
Log.d(TAG, "Scrolling left");
scrollingLeft =true;
scrollView.smoothScrollBy(-pace, 0);
if(!scrollView.canScrollHorizontally(-1)) // reached the furthest left turn of scrolling left
scrollingLeft = false;
}
}
});
}
}, 3000, 50);
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I have some problem ListView in ScrollView not displaying all items
and I try this code, it works but it takes a long time to process in the Adapter.
I have tried this code which is faster but doesn't display all items
How do I fix it?
Note: my ListView id is lv_poll_feed
<?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="#color/color_white">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/lay_edit_comment"
android:scrollbars="none">
<RelativeLayout
android:id="#+id/lay_big"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/lay_body_timeline_detail_detail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/view_line_4">
<TextView
android:id="#+id/tx_time_timeline_detail_user"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:padding="10dp"
android:text="-"
android:textColor="#color/color_gray_light"
android:textSize="#dimen/tx_size_smally_time"/>
<RelativeLayout
android:id="#+id/lay_profile_detail_detail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tx_time_timeline_detail_user"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp">
<TextView
android:id="#+id/tx_timeline_detail_detail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:padding="10dp"
android:text="-"
android:textColor="#color/tx_color_token"
android:textSize="#dimen/tx_size_small"/>
<RelativeLayout
android:id="#+id/lay_center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/tx_timeline_detail_detail"
android:layout_marginBottom="5dp"
android:layout_marginTop="10dp"
android:gravity="center"
android:visibility="visible">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/tx_catego_topic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:background="#drawable/bg_button"
android:padding="5dp"
android:text="xxxxxxx"
android:textColor="#color/color_white"
android:textSize="#dimen/tx_size_small"
android:visibility="gone"/>
<com.cunoraz.tagview.TagView xmlns:tagview="http://schemas.android.com/apk/res-auto"
android:id="#+id/tagCloudLinkView_topic"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
tagview:lineMargin="5dp"
tagview:tagMargin="5dp"
tagview:theme="#style/AppTheme"/>
<ListView
android:id="#+id/lv_poll_feed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:divider="#null"
android:visibility="visible">
</ListView>
</LinearLayout>
</RelativeLayout>
<ImageView
android:id="#+id/img_timeline_profile_detail_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/tx_timeline_detail_detail"
android:adjustViewBounds="true"
android:visibility="visible"/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/lay_timeline_detail_emoji"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/lay_profile_detail_detail"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:focusable="false"
android:focusableInTouchMode="false"
android:padding="10dp">
<LinearLayout
android:id="#+id/lay_big_emoji"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="visible"
android:weightSum="3">
<LinearLayout
android:id="#+id/lay_emoji1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:orientation="horizontal"
android:visibility="visible">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:src="#drawable/amazed_1"/>
<TextView
android:id="#+id/tx_number_emoji_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=""
android:textSize="#dimen/tx_size_smally_time"/>
</LinearLayout>
<LinearLayout
android:id="#+id/lay_emoji2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="0"
android:orientation="horizontal"
android:visibility="visible">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:src="#drawable/funny_2"/>
<TextView
android:id="#+id/tx_number_emoji_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=""
android:textSize="#dimen/tx_size_smally_time"/>
</LinearLayout>
<LinearLayout
android:id="#+id/lay_emoji3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="0"
android:orientation="horizontal"
android:visibility="visible">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:src="#drawable/love_3"/>
<TextView
android:id="#+id/tx_number_emoji_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="#dimen/tx_size_smally_time"/>
</LinearLayout>
<LinearLayout
android:id="#+id/lay_emoji4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="0"
android:orientation="horizontal"
android:visibility="visible">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:src="#drawable/sorrow_2"/>
<TextView
android:id="#+id/tx_number_emoji_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=""
android:textSize="#dimen/tx_size_smally_time"/>
</LinearLayout>
<LinearLayout
android:id="#+id/lay_emoji5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="0"
android:orientation="horizontal"
android:visibility="visible">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:src="#drawable/anger_5"/>
<TextView
android:id="#+id/tx_number_emoji_5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=""
android:textSize="#dimen/tx_size_smally_time"/>
</LinearLayout>
<LinearLayout
android:id="#+id/lay_emoji6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="0"
android:orientation="horizontal"
android:visibility="visible">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:src="#drawable/horrified_6"/>
<TextView
android:id="#+id/tx_number_emoji_6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=""
android:textSize="#dimen/tx_size_smally_time"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<View
android:id="#+id/view_line_5"
android:layout_below="#+id/lay_timeline_detail_emoji"
android:layout_marginTop="5dp"
android:background="#color/text_bottombar"/>
<RelativeLayout
android:id="#+id/lay_body_quest_topic"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/view_line_5"
android:layout_marginTop="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="6">
<LinearLayout
android:id="#+id/lay_timeline_detail_up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="2"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="center"
android:orientation="horizontal"
android:padding="5dp">
<ImageView
android:id="#+id/img_up"
android:layout_width="20dp"
android:layout_height="20dp"
android:src="#drawable/up_1"/>
<TextView
android:id="#+id/tx_timeline_detail_up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:text="#string/tx_up"
android:textColor="#color/tx_color_token"
android:textSize="#dimen/tx_size_smally"/>
<TextView
android:id="#+id/tx_timeline_detail_number_up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text=" 53"
android:textColor="#color/tx_color_token"
android:textSize="#dimen/tx_size_smally"/>
</LinearLayout>
<LinearLayout
android:id="#+id/lay_timeline_detail_comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="2"
android:gravity="center"
android:orientation="horizontal"
android:padding="5dp">
<ImageView
android:id="#+id/img_comment"
android:layout_width="20dp"
android:layout_height="20dp"
android:src="#drawable/comment_1"/>
<TextView
android:id="#+id/tx_timeline_detail_comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:text="#string/tx_comment"
android:textColor="#color/tx_color_token"
android:textSize="#dimen/tx_size_smally"/>
<TextView
android:id="#+id/tx_timeline_detail_number_comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text=" 53"
android:textColor="#color/tx_color_token"
android:textSize="#dimen/tx_size_smally"/>
</LinearLayout>
<LinearLayout
android:id="#+id/lay_profile_detail_share"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="2"
android:gravity="center"
android:orientation="horizontal"
android:padding="5dp">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:src="#drawable/share_1"/>
<TextView
android:id="#+id/tx_timeline_detail_share"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:text="#string/tx_share"
android:textColor="#color/tx_color_token"
android:textSize="#dimen/tx_size_smally"/>
<TextView
android:id="#+id/tx_timeline_detail_number_share"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text=" "
android:textColor="#color/tx_color_token"
android:textSize="#dimen/tx_size_smally"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<View
android:id="#+id/view_line_3"
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_below="#+id/lay_body_quest_topic"
android:layout_marginTop="5dp"
android:background="#color/bottombar"/>
<RelativeLayout
android:id="#+id/lay_timeline_detail_select_emoji_profile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/lay_body_quest_topic"
android:layout_marginBottom="-10dp"
android:background="#drawable/bg_emoji"
android:visibility="gone">
<LinearLayout
android:id="#+id/lay_star"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/tx_name_detail"
android:gravity="center"
android:orientation="horizontal">
<RadioGroup
android:id="#+id/radioGroupQuest"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal"
android:padding="0dp">
<RadioButton
android:id="#+id/emoji1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:background="#drawable/img_emoji_amazed"
android:button="#android:color/transparent"
android:checked="false"
android:gravity="center"/>
<RadioButton
android:id="#+id/emoji2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:background="#drawable/img_emoji_funny"
android:button="#android:color/transparent"
android:checked="false"/>
</RadioGroup>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
</ScrollView>
You should not add same direction scrolling layout inside another scrolling layout. Result will not always intended. Here your listview is wrapping to single element of your ListView because you have added it inside Scrollview. You should not do that in first place but if you can't change your layout then do the following changes:
Change ListView to RecyclerView and change the adapter accordingly.
Also, change ScrollView to NestedScrollView.
You can use this function :
public static void setListViewHeight(ListView listView) {
ListAdapter listAdapter = listView.getAdapter();
if (listAdapter == null)
return;
int desiredWidth = MeasureSpec.makeMeasureSpec(listView.getWidth(), MeasureSpec.UNSPECIFIED);
int totalHeight = 0;
View view = null;
for (int i = 0; i < listAdapter.getCount(); i++) {
view = listAdapter.getView(i, view, listView);
if (i == 0)
view.setLayoutParams(new ViewGroup.LayoutParams(desiredWidth, LayoutParams.WRAP_CONTENT));
view.measure(desiredWidth, MeasureSpec.UNSPECIFIED);
totalHeight += view.getMeasuredHeight();
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
listView.setLayoutParams(params);
}
and set like this :
ListView list = (ListView) view.findViewById(R.id.listview);
setListViewHeight(list);
I have create a list of Currency exchange rate by using table with 6 row.
i want 6 row to have some animation like it running up and down automatically in some period of time so it can make user user more attractive on it.
please give me some example or if you have any idea to make table row animation that make more attractive for user.
Move the scrolled position of your view.
public void scrollBy (int x, int y)
Parameters
x - the amount of pixels to scroll by horizontally
y - the amount of pixels to scroll by vertically
lv.scrollBy(100,100) //....like this
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_margin="0sp"
android:layout_weight="0.03"
android:background="#drawable/gradient">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/logo"
android:layout_marginLeft="50dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="35dp"
android:layout_marginTop="10dp"
android:text="GOLDEN ROYAL EXCHANGE"
android:textColor="#ba8707"
android:textStyle="bold"
android:textSize="16sp"
android:backgroundTintMode="multiply"
android:shadowColor="#030303"
android:phoneNumber="true" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_margin="1sp"
android:background="#drawable/lineback"
android:layout_weight="0.62">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/myScrollview"
android:scrollbars="none">
<TableLayout
android:id="#+id/table01"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow
android:background="#4042dba8"
android:id="#+id/khmerrow"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:minHeight="145px"
android:layout_marginTop="3dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="3dp"
android:src="#drawable/khmerflages" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="-8dp"
android:text="Khmer Riel 柬币"
android:textColor="#000000"
android:textSize="13sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:text="USD/KHR"
android:textColor="#000000"
android:textSize="12sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="30dp"
android:text="4,200"
android:textColor="#000000"
android:textSize="13sp"
android:textStyle="bold" />
</TableRow>
<TableRow android:background="#4042dba8"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:minHeight="145px"
android:layout_marginTop="2.5sp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="3dp"
android:src="#drawable/thaiflags" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="-12dp"
android:layout_gravity="center"
android:text="Thai Baht 泰铢"
android:textColor="#000000"
android:textSize="13sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="25dp"
android:text="USD/THB"
android:textColor="#000000"
android:textSize="12sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="30dp"
android:text="35"
android:textColor="#000000"
android:textSize="13sp"
android:textStyle="bold" />
</TableRow>
<TableRow android:background="#4042dba8"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:minHeight="145px"
android:layout_marginTop="2.5sp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="3dp"
android:src="#drawable/chinaflags" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="-3dp"
android:layout_gravity="center"
android:text="China RMB 人民币"
android:textColor="#000000"
android:textSize="13sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="18dp"
android:text="USD/RMB"
android:textColor="#000000"
android:textSize="12sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="30dp"
android:text="6.7"
android:textColor="#000000"
android:textSize="13sp"
android:textStyle="bold" />
</TableRow>
<TableRow android:background="#4042dba8"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:minHeight="145px"
android:layout_marginTop="2.5sp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="3dp"
android:src="#drawable/hongkongflags" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="9dp"
android:layout_gravity="center"
android:text="HongKong Dollar 港币"
android:textColor="#000000"
android:textSize="13sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="8dp"
android:text="USD/HKD"
android:textColor="#000000"
android:textSize="12sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="30dp"
android:text="8.7"
android:textColor="#000000"
android:textSize="13sp"
android:textStyle="bold" />
</TableRow>
<TableRow android:background="#4042dba8"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:minHeight="145px"
android:layout_marginTop="2.5sp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="3dp"
android:src="#drawable/malaysiaflags" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_gravity="center"
android:text="Malaysia MYR 马币"
android:textColor="#000000"
android:textSize="13sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="15dp"
android:text="USD/MYR"
android:textColor="#000000"
android:textSize="12sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="30dp"
android:text="6.6"
android:textColor="#000000"
android:textSize="13sp"
android:textStyle="bold" />
</TableRow>
<TableRow android:background="#4042dba8"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:minHeight="145px"
android:layout_marginTop="2.5sp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="3dp"
android:src="#drawable/singaporeflags" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_gravity="center"
android:text="Singapore SGD 新币"
android:textColor="#000000"
android:textSize="13sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="15dp"
android:text="USD/SGD"
android:textColor="#000000"
android:textSize="12sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="30dp"
android:text="1.6"
android:textColor="#000000"
android:textSize="13sp"
android:textStyle="bold" />
</TableRow>
<TextView
android:layout_width="match_parent"
android:layout_height="33dp"
android:layout_marginTop="2.5sp"
android:textColor="#000000"
android:id="#+id/date" />
</TableLayout>
</ScrollView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_margin="1sp"
android:background="#dee6d461"
android:layout_weight="0.36">
<ViewFlipper
android:id="#+id/bckgrndViewFlipper1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="#+id/bckgrndImageView8"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="centerCrop"
android:src="#drawable/exchange1" />
<ImageView
android:id="#+id/bckgrndImageView7"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="centerCrop"
android:src="#drawable/exchange2" />
<ImageView
android:id="#+id/bckgrndImageView6"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="centerCrop"
android:src="#drawable/exchange3" />
<ImageView
android:id="#+id/bckgrndImageView5"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="centerCrop"
android:src="#drawable/exchange4" />
<ImageView
android:id="#+id/bckgrndImageView4"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="centerCrop"
android:src="#drawable/exchange5" />
<ImageView
android:id="#+id/bckgrndImageView3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="centerCrop"
android:src="#drawable/exchange6" />
</ViewFlipper>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="25dp"
android:background="#drawable/gradient">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/trading"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:text="Trading Hours .................`enter code here`"
android:textSize="13sp"
android:textColor="#ba8707"/>
</LinearLayout>
</LinearLayout>
public class MainActivity extends AppCompatActivity {
Animation fade_in, fade_out, rowanimation;
ViewFlipper viewFlipper;
ScrollView myView;
TextView date;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
viewFlipper = (ViewFlipper) this.findViewById(R.id.bckgrndViewFlipper1);
fade_in = AnimationUtils.loadAnimation(this,
android.R.anim.fade_in);
fade_out = AnimationUtils.loadAnimation(this,
android.R.anim.fade_out);
viewFlipper.setInAnimation(fade_in);
viewFlipper.setOutAnimation(fade_out);
viewFlipper.setAutoStart(true);
viewFlipper.setFlipInterval(5000);
viewFlipper.startFlipping();
}
}
I am trying to implement an onclick for the entire layout but it won't work.
Here is my function for my RelativeLayout:
public void updateRange(View v)
{
System.out.println("Hello!");
}
and here is my xml:
<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="wrap_content"
tools:context=".MainActivity"
android:background="#ffffffff"
android:id="#+id/xasdf"
android:onClick="updateRange">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/toptab"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Settings"
android:fontFamily="monospace"
android:textAllCaps="false"
android:layout_weight="0.333333"
android:id="#+id/settingsButton"
android:background="#fffdb64b" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Solutions"
android:fontFamily="monospace"
android:textAllCaps="false"
android:layout_weight="0.333333"
android:id="#+id/solutionsButton"
android:background="#fffdb64b" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mode"
android:fontFamily="monospace"
android:textAllCaps="false"
android:layout_weight="0.333333"
android:id="#+id/modeButton"
android:background="#fffdb64b" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:gravity="center_vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/chartlayout"
android:layout_below="#+id/toptab"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:weightSum="1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<EditText
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/textView"
android:layout_weight="0.5"
android:background="#ffffffff"
android:fontFamily="monospace"
android:hint="y = ..." />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Graph"
android:fontFamily="monospace"
android:textAllCaps="false"
android:layout_weight="0.25"
android:id="#+id/button"
android:background="#ffd0d0d0"
android:onClick="drawGraph" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Table"
android:fontFamily="monospace"
android:layout_weight="0.25"
android:textAllCaps="false"
android:id="#+id/button2"
android:background="#ffd0d0d0" />
</LinearLayout>
</RelativeLayout>
Try adding the extra line below to your Relative Layout description:
...
android:onClick="updateRange"
android:clickable="true">