I want to create a animation with some dots and they are falling from top to bottom. For that I am using a translate animation which moves the dots images from top to bottom. But I want this to be continuous meaning the animation should repeat itself.
I have to create a animation with some dots and they are falling from top to bottom i will post gif animation file , which is my requirement , please anyone guide me how to create this one?
it starts with FadeIn animation it is running fine in my code and then the dots moving in continuous Motion from TOP TO BOTTOM as in gif i have posted it is not working in my code i have created 14 Linearlayouts they contains 7 texviews Horizontally with VISIBILITY.GONE in Oncreate i am changing its VISIBILITY to VISIBLE and starting FADE IN animation and i will post my code , please anyone guide me?
MY REQUIREMNET
rain_like_animation
public class MainActivity extends Activity implements AnimationListener {
LinearLayout move_animation, move_animation1, move_animation2,
move_animation3, move_animation4, move_animation5;
Display display;
Point size2;
int width1, height1;
// Animation
Animation animFadein;
TranslateAnimation translateanimation;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
display = getWindowManager().getDefaultDisplay();
size2 = new Point();
display.getSize(size2);
width1 = size2.x;
height1 = size2.y;
move_animation = (LinearLayout) findViewById(R.id.move_animation);
move_animation1 = (LinearLayout) findViewById(R.id.move_animation1);
move_animation2 = (LinearLayout) findViewById(R.id.move_animation2);
move_animation3 = (LinearLayout) findViewById(R.id.move_animation3);
// load the animation
animFadein = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.fade_in);
// set animation listener
animFadein.setAnimationListener(this);
// (float fromXDelta, float toXDelta, float fromYDelta, float toYDelta)
translateanimation = new TranslateAnimation(0.0f, 0.0f, -50.0f, height1);
translateanimation.setDuration(3000);
translateanimation.setRepeatCount(Animation.INFINITE);
translateanimation.setRepeatMode(Animation.RESTART);
translateanimation.setFillAfter(false);
translateanimation.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
Log.e("onAnimationStart", "onAnimationStart");
}
#Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
Log.e("onAnimationRepeat", "onAnimationRepeat");
}
#Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
Log.e("onAnimationEnd", "onAnimationEnd");
}
});
move_animation.setVisibility(View.VISIBLE);
move_animation1.setVisibility(View.VISIBLE);
move_animation2.setVisibility(View.VISIBLE);
move_animation3.setVisibility(View.VISIBLE);
// start the Fadein animation
// =============================================
// =============================================
move_animation.startAnimation(animFadein);
move_animation1.startAnimation(animFadein);
move_animation2.startAnimation(animFadein);
move_animation3.startAnimation(animFadein);
}
#Override
public void onAnimationEnd(Animation animation) {
// Take any action after completing the animation
// start the translate animation when fade-in stops
move_animation.startAnimation(translateanimation);
move_animation1.startAnimation(translateanimation);
move_animation2.startAnimation(translateanimation);
move_animation3.startAnimation(translateanimation);
}
#Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
}
<LinearLayout 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:background="#drawable/splashimage"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/move_animation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:orientation="horizontal"
android:visibility="gone"
android:weightSum="7" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_blue_bright" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_red_dark" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_blue_bright" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_red_dark" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_blue_bright" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_red_dark" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_blue_bright" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/move_animation1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:orientation="horizontal"
android:visibility="gone"
android:weightSum="7" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_blue_bright" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_red_dark" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_blue_bright" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_red_dark" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_blue_bright" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_red_dark" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_blue_bright" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/move_animation2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:orientation="horizontal"
android:visibility="gone"
android:weightSum="7" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_blue_bright" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_red_dark" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_blue_bright" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_red_dark" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_blue_bright" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_red_dark" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_blue_bright" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/move_animation3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:orientation="horizontal"
android:visibility="gone"
android:weightSum="7" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_blue_bright" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_red_dark" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_blue_bright" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_red_dark" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_blue_bright" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_red_dark" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_blue_bright" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Download this library https://github.com/plattysoft/Leonids
Add this to your project dependency
then
new ParticleSystem(RainActivity.this, 80, R.drawable.rain_drop, 10000)
.setSpeedByComponentsRange(0f, 0f, 0.05f, 0.1f)
.setAcceleration(0.00005f, 90)
.emitWithGravity(findViewById(R.id.cloud), Gravity.BOTTOM, 8);
It will look like
Related
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);
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 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
}
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">
In one of my project I want to create a layout like given Image
In image assume that Red boxes are Textviews and Blue boxes are EditText
The number of rows is not known. It depends on web service Response. How can I achieve this.
You can try like this codes. Such as
<LinearLayout 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:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3" >
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="First Row" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="First Row" />
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="First Row" />
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="First Row" />
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="First Row" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="First Row" />
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="First Row" />
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="First Row" />
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="First Row" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="First Row" />
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="First Row" />
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="First Row" />
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="First Row" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="First Row" />
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="First Row" />
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="First Row" />
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="First Row" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:orientation="horizontal" >
<Button
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Ok" />
<Button
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Cancel" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
I expect it will be helpful for you. Best of luck!
Try adding views dynamically in linear layout which is inside scroll view.
Try this code.I know it is not exact solution.But,Hope it gives you some idea.
public class MainActivity extends Activity {
ScrollView scrollview;
LinearLayout linearLayout;
LinearLayout.LayoutParams layoutParams;
static int i;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
scrollview = (ScrollView)findViewById(R.id.scrollview);
linearLayout = (LinearLayout)findViewById(R.id.linearlayout);
Button button = (Button)findViewById(R.id.button);
layoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
button.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
TextView view = new TextView(MainActivity.this);
view.setText(++i+" view");
linearLayout.addView(view, layoutParams);
}
});
}}
first inf_child.xml layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/inf_dynamicLl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:id="#+id/btnContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="0.25"
android:text="OK"/>
<Button
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="0.25"
android:text="Cancel"/>
</LinearLayout>
</LinearLayout>
second inf_dynamic_view.xml layout which will generate row dynamically:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/inner_linear_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:id="#+id/firstText"
android:layout_width="0dp"
android:layout_weight="0.25"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/secontText"
android:layout_width="0dp"
android:layout_weight="0.25"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/ThirdText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.25" />
<EditText
android:id="#+id/editText"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="0.25"
/>
</LinearLayout>
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) mContext.getSystemService(mContext.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.inf_child, null);
}
LinearLayout dynamicLl = (LinearLayout) convertView.findViewById(R.id.inf_dynamicLl);
for (int rowCounter = 0; rowCounter < parentData.get(groupPosition).childData.get(childPosition).price.size(); rowCounter++)
createRow(dynamicLl, parentData.get(groupPosition).childData.get(childPosition).price.get(rowCounter), groupPosition);
=> create row dynamically
private void createRow(LinearLayout lView, String price, int childPosition) {
LayoutInflater vi = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View l = vi.inflate(R.layout.inf_dynamic_view, null);
final TextView tvFirst, tvSecond,tvThird;
final EditText edt1;
lView.addView(l);
lView.refreshDrawableState();
}