I am trying to print dynamic horizontal lines in Android. I want to display the lines with some specific margin-left gap but i think all the lines are getting displayed in one place so , i am displaying all the lines in one place.
My Code :
MainActivity.java
package com.example.testlinear;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.app.Activity;
import android.graphics.Color;
public class MainActivity extends Activity
{
LinearLayout lnr;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lnr = (LinearLayout)findViewById(R.id.lnr);
int x = 5;
lnr.setOrientation(LinearLayout.HORIZONTAL);
View[] vv = new View[x];
for(int i=0;i<x;i++)
{
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(1,50);
vv[i] = new View(MainActivity.this);
vv[i].setBackgroundColor(Color.BLACK);
vv[i].setLayoutParams(params);
vv[i].setPadding(50+i*10, 40, 0, 0);
lnr.addView(vv[i]);
}
}
}
activity_main.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="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<LinearLayout
android:id="@+id/lnr"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
</LinearLayout>
</RelativeLayout>
Output Image:
These are all codes and output image , please let me know , how can i print 5 lines with some specific gaps.
Please suggest me some good solution.