android-relativelayout

How to add a view programmatically to RelativeLayout?

别等时光非礼了梦想. 提交于 2019-11-27 11:45:40
Can you give me a very simple example of adding child view programmatically to RelativeLayout at a given position? For example, to reflect the following XML: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginLeft="107dp" android:layout_marginTop="103dp"

What's the difference between alignBaseline and alignBottom in Android?

左心房为你撑大大i 提交于 2019-11-27 11:10:40
问题 I tried both to align a few TextView objects and they gave me the same results. What exactly is the difference between 'baseline' and 'bottom' ? 回答1: To visualize the difference, I usually imagine two textboxes in Word or Photoshop. alignBottom lines up the bottom of the textboxes. (The blue outline) Text could be uneven, but the boxes they're in would line up on the bottom. alignBaseline aligns the actual text within the box. This can help ensure that the texts line up on the bottom,

How to switch from the default ConstraintLayout to RelativeLayout in Android Studio

蓝咒 提交于 2019-11-27 10:47:52
I have the latest android Studio (2.3 beta 3) and it seems ConstraintLayout is the default when creating a project. How can I make Android Studio use the RelativeLayout as the default layout element for new projects ? Well, I saw the answer above and it worked for me too. But, I gave it a shot, and succeded converting my current project to Relative Layout. Do as follows: At activity_main.xml tab, change it to text. At the top of it, you'll find the following: <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" Just change all before xmlns to

How to get RelativeLayout working with merge and include?

橙三吉。 提交于 2019-11-27 10:12:19
I have been trying for a few days now to make my layouts more efficient by converting from using several levels of nested LinearLayouts to one RelativeLayout and have come across a few problems that I haven not been able to find a workaround for... I have searched the Android beginners group and this site and have not been able to find anything that would help me solve the problem. I read on one of the blogs that you can combine layouts with merge and include tags. So what I have is a main layout file with a RelativeLayout root element. Inside of that I have 5 include tags that reference 5

How do I programmatically remove an existing rule that was defined in XML?

╄→尐↘猪︶ㄣ 提交于 2019-11-27 07:31:45
I have a linear layout that is contained inside a relative layout. It is set in the XML file to be to the right of another linear layout (this works fine). In some cases I want to change the relative position of the layout during the onCreate of the activity so I need to modify the "to the right of" param to relate to another layout. I tryed this: RelativeLayout.LayoutParams layoutParams; layoutParams = (RelativeLayout.LayoutParams) linearLayoutToMove .getLayoutParams(); layoutParams.addRule(RelativeLayout.RIGHT_OF, R.id.new_ref_LinearLayout); But it does not work :o( Any clues ? Michael You

Android RelativeLayout programmatically Set “centerInParent”

自闭症网瘾萝莉.ら 提交于 2019-11-27 05:03:01
问题 I have a RelativeLayout like this: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="10dip"> <Button android:id="@+id/negativeButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="20dip" android:textColor="#ffffff" android:layout_alignParentLeft="true" android:background="@drawable/black_menu

how to maintain Visibllity of recyclerview item in adapter class

不羁的心 提交于 2019-11-27 04:53:45
问题 I have a layout like bellow in my Adapter : <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:card_view="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#FFFFFF"> <android.support.v7.widget.CardView android:id="@+id/cardVisibleLayout" android:layout_width="match_parent" android:layout

What is the baseline in RelativeLayout?

老子叫甜甜 提交于 2019-11-27 01:26:18
问题 What does "baseline" refer to when used in the context of a relative layout? Simple question, probably, but the documentation and google offer no hints. 回答1: The term baseline comes from typography. It's the invisible line letters in text sit on. For example, imagine you put two TextView elements next to each other. You give the second TextView a big padding (say 20dp). If you add layout_alignBaseline to the second element, the text will "scoot up" to align with the baseline of the first

How do I set background image with picasso in code

China☆狼群 提交于 2019-11-26 23:06:25
问题 I know picasso loads image into imageview etc but how do I set my layout background image using picasso? My code: public class MainActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.relativelayout); relativeLayout.setBackgroundResource(R.drawable.table_background); Picasso.with(MainActivity.this) .load(R

ImageView fills parent's width OR height, but maintains aspect ratio

半城伤御伤魂 提交于 2019-11-26 22:39:43
问题 I have a square image (though this problem also applies to rectangular images). I want to display the image as large as possible, stretching them if necessary, to fill their parents, while still maintaining the aspect ratio. The image is smaller than the ImageView. The problem is, I can't stretch the image and "match" the height and width of the ImageView. This is my XML layout file: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res