Problems laying out TextViews within a Relative Layout(which is inside a main Relative Layout)
Tag : android , By : Kristian Hofslaeter
Date : March 29 2020, 07:55 AM
hop of those help? I think you need to envelop your TextViews in a vertically oriented LinearLayout. Add both of your TextViews to a LinearLayout instead of the RelativeLayout, then add the LinearLayout to the RelativeLayout with the position parameters you want. Here's an example: LinearLayout linearLayout = new LinearLayout(this);
linearLayout.setOrientation( LinearLayout.VERTICAL );
TextView menuItemTitle = new CustomTextView(this);
menuItemTitle.setText("All You Can Eat");
menuItemTitle.setTextSize(30);
menuItemTitle.setBackgroundColor(Color.TRANSPARENT);
menuItemTitle.setTextColor(Color.WHITE);
LinearLayout.LayoutParams menuItemTitleParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
menuItemTitleParams.gravity = Gravity.CENTER_HORIZONTAL;
menuItemTitle.setLayoutParams(menuItemTitleParams);
TextView menuItemDesc = new CustomTextView(this);
menuItemDesc.setText("All you can ribs, chicken, pork and sides you can stomach to eat\nAlso includes dessert!");
menuItemDesc.setTextSize(15);
menuItemDesc.setBackgroundColor(Color.TRANSPARENT);
menuItemDesc.setTextColor(Color.WHITE);
menuItemDesc.setLayoutParams(menuItemTitleParams);
linearLayout.addView(menuItemTitle);
linearLayout.addView(menuItemDesc);
|
Trouble getting relative layout right
Date : March 29 2020, 07:55 AM
This might help you I have been pulling my hair out trying to get my relative layout setup the way I want. I want to have a EditText on the left with a TextView in the middle and a Button to the right and all those over a ListView Here is as close as I can get ... , Try this <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<EditText
android:id="@+id/new_bookmark_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/new_bookmark_clock"
android:layout_alignBaseline="@+id/btn_add_new_bookmark"
android:ems="10"
android:inputType="text" />
<TextView
android:id="@+id/new_bookmark_clock"
android:layout_width="wrap_content"
android:layout_alignBaseline="@+id/btn_add_new_bookmark"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/btn_add_new_bookmark"
android:text="@string/xx_xx_xx" />
<Button
android:id="@+id/btn_add_new_bookmark"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="@string/add" />
<ListView
android:id="@+id/bookmark_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/new_bookmark_name" />
</RelativeLayout>
|
Linear Layout in side Relative Layout I want to change the color of Relative Layout on Press.
Date : March 29 2020, 07:55 AM
Any of those help If you are using your layout as part of listview, then why you are giving selector to that layout. You can make use of selector in listview. Pls try this out. It may sometimes help you: <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="70dp"
>
<RelativeLayout
android:id="@+id/itemLayoutView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:background="@drawable/listview_row_background_selector"
android:paddingLeft="@dimen/list_view_layout_margin" >
<LinearLayout
android:id="@+id/itemLinearLayoutView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:clickable="true"
android:orientation="vertical" >
<TextView
android:id="@+id/gameNameView"
android:layout_width="wrap_content"
android:layout_height="36dp"
android:textSize="@dimen/game_list_text_size" />
<TextView
android:id="@+id/gameCreationDateView"
android:layout_width="wrap_content"
android:layout_height="24dp"
android:textColor="@color/gray"
android:textSize="@dimen/small_text_size"
android:textStyle="italic" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
|
Understanding multiplier in auto layout to use relative positioning
Date : March 29 2020, 07:55 AM
wish helps you There are a couple ways to do this. In the simplest case, you've already almost got it: if you want the horizontal boundaries to be at 10% and 90%, then you need to specify both constraints with respect to the trailing edge of the superview -- so Subview.Trailing locks to Superview.Trailing with a multiplier of 0.9, as you say, but then Subview.Leading also locks to Superview.Trailing, just with a multiplier of 0.1:
|
Having trouble with my XML: using layout_above in Relative Layout
Date : March 29 2020, 07:55 AM
hope this fix your issue The id is defined in the Button after it is referenced in EditText. Instead build your layout by first defining the button, and then defining the EditText to be above.
|