Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to program relativeLayouts in code
    primarykey
    data
    text
    <p>I need to create a dinamic table which will be fit with rows of data. The rows I want will have an specific form, like this:</p> <p><img src="https://i.stack.imgur.com/K4bDO.png" alt="http://i.imgur.com/1D8ge.png"></p> <p>So, to get it, I used relativeLayouts. The problem is that I first tried it with an .xml to see what parameters will have the differents views that it forms, and I get it, but now I cant replicate it in the code.</p> <p>Here is my code:</p> <pre><code>TableLayout linkRoutesTable = (TableLayout) findViewById(R.id.layoutLinkRoutes); //ROW: TableRow linkRouteRow = new TableRow(this); linkRouteRow.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); linkRouteRow.setId(i) //RELATIVELAYOUT: float px0 = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, r.getDisplayMetrics()); RelativeLayout relativeLayout = new RelativeLayout(this); relativeLayout.setLayoutParams(new RelativeLayout.LayoutParams(0, (int)px0))); //CONTENT: // BUTTON: ... // NUMBER:... // ADDRESS:... // NAME: ... relativeLayout.addView(number); relativeLayout.addView(name); relativeLayout.addView(address); relativeLayout.addView(button); linkRouteRow.addView(relativeLayout); linkRouteTable.addView(linkRouteRow); linkRoutesTable.refreshDrawableState(); </code></pre> <p>It doesn't show anything...</p> <p>The .xml show ok, here it is:</p> <pre><code>&lt;TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="center" android:orientation="vertical"&gt; &lt;TableRow&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="0dp" android:layout_weight="1" android:id="@+id/layoutLinkRoutes" &gt; &lt;Button android:text="Button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button1" android:layout_alignParentTop="true" android:layout_alignParentRight="true"&gt;&lt;/Button&gt; &lt;TextView android:textStyle="bold" android:textSize="45dp" android:text="1" android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:layout_marginLeft="22dp"&gt;&lt;/TextView&gt; &lt;TextView android:text="TextView" android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/button1" android:layout_toRightOf="@+id/textView1" android:layout_marginLeft="16dp"&gt;&lt;/TextView&gt; &lt;TextView android:text="TextView" android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:layout_alignParentTop="true" android:layout_alignLeft="@+id/textView3"&gt;&lt;/TextView&gt; &lt;/RelativeLayout&gt; &lt;/TableRow&gt; </code></pre> <p>What Am I doing wrong in the code? I need some help, I tried everything.</p> <p>If I dont use the relativeLayouts and the rows, it shows something but bad... so the problem is the rows and the relativelayout</p> <p>Really thanks...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload