hello friends i am new android, i need your help.
my problem is i am adding textview array in linear layout Dynamic way. but when it's reach near device screen width its not wrap contenting .
like this way :
here is my xml file code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relative_read_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="fill_horizontal" >
<RelativeLayout
android:id="@+id/bar_alphabet"
android:layout_width="match_parent"
android:layout_height="@dimen/single_gridviewHeight"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="@drawable/bar_alphabet"
android:paddingTop="7dp" >
<LinearLayout
android:id="@+id/linelay_bar_alphabet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:id="@+id/relative_read_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/toolbar"
android:layout_below="@+id/bar_alphabet"
android:background="@drawable/background_reading9"
android:gravity="left" >
<LinearLayout
android:id="@+id/linelay_wordIn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/toolbar"
android:layout_below="@+id/bar_alphabet"
android:layout_marginLeft="180dp"
android:layout_marginTop="280dp"
android:background="@android:color/darker_gray"
android:orientation="horizontal" >
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:id="@+id/toolbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="@drawable/toolbar"
android:paddingLeft="15dp"
android:paddingRight="15dp" >
<ImageButton
android:id="@+id/imgbttn_help"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="@android:color/transparent"
android:onClick="onclick"
android:scaleType="fitXY"
android:src="@drawable/help1" />
</RelativeLayout>
<ImageView
android:id="@+id/img_help"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:onClick="onclick"
android:scaleType="fitXY"
android:visibility="gone" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</LinearLayout>
code for adding textview in linear layout
public static ArrayList<TextView> sentence(String[] arr) {
if (linelay_wordIn.getChildCount() > 0)
linelay_wordIn.removeAllViews();
if (allTextView != null) {
allTextView.remove(txt);
allTextView.clear();
System.out.println("hello remove all textview here");
} else {
System.out.println("hello all textview array is null here");
}
String str1 = "";
for (int i = 0; i < arr.length; i++) {
str1 = str1 + arr[i].toString();
System.out.println(" senctence separte in word " + arr[i]
+ " words" + arr.length);
}
/* listview for getting textview */
System.out.println("sentence " + str1.toString() + "str1 length :: "
+ str1.length());
WindowManager wm = (WindowManager) contextG
.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
int maxWidth = display.getWidth() - 20;
txt = new TextView[arr.length];
for (int j = 0; j < arr.length; j++) {
txt[j] = new TextView(contextG);
txt[j].setId(j);
// txt[j].setTag(sent_audio1[j]);
txt[j].setBackgroundResource(Color.TRANSPARENT);
txt[j].setTextSize(60);
txt[j].setTypeface(
Typeface.createFromAsset(contextG.getAssets(), "TIMES.TTF"),
Typeface.BOLD);
// if (arr.length >= 5) {
//
// } else {
txt[j].setText(arr[j]);
// }
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1f);
lp.setMargins(2, 2, 2, 2);
txt[j].setLayoutParams(lp);
txt[j].setTextColor(Color.BLACK);
txt[j].setClickable(true);
txt[j].setDuplicateParentStateEnabled(true);
txt[j].setFocusableInTouchMode(true);
txt[j].setFocusable(true);
txt[j].setOnTouchListener(myListener);
// System.out.println("txt[j]" + j + "id " + txt[j].getId());
allTextView.add(txt[j]); /* add textview into arraylist */
// System.out.println("id" + allTextView.get(j).getId() +
// "text "
// + allTextView.get(j).getText().toString());
// System.out.println("x" + allTextView.get(j).getX() + "y "
// + allTextView.get(j).getY());
// if (linelay_wordIn.getChildCount() > 5) {
// txt[j].setText(arr[j] + "\n");
// }
linelay_wordIn.addView(txt[j], lp);
// linelay_wordIn.getChildAt(j).getX();
// System.out.println("y " +
// linelay_wordIn.getChildAt(j).getX());
}
return allTextView;
}
i dnot know how to solve this problem very quick way or easy way. if anybody can suggest better way that will helpful to me. Thanks in advance.