android-linearlayout

Android: Add two text views programmatically

拜拜、爱过 提交于 2020-04-04 11:39:48
问题 I am trying to add Views to a linear layout programmatically. LinearLayout layout = (LinearLayout) findViewById(R.id.info); String [] informations = topOffer.getInformations(); TextView informationView; View line = new View(this); line.setLayoutParams(new LayoutParams(1, LayoutParams.FILL_PARENT)); line.setBackgroundColor(R.color.solid_history_grey); for (int i = 0; i < informations.length; i++) { informationView = new TextView(this); informationView.setText(informations[i]); layout.addView

layout_gravity not working in horizontal linear layout

心不动则不痛 提交于 2020-03-17 05:40:26
问题 I have been trying to use layout_gravity in a horizontal linear layout . But it doesn't seem to work. I don't want to use a relative layout or any other layout. I want to know why it is not working with linear layout .I have earlier used layout_gravity in vertical linear layouts and it has worked in the way I expected. <LinearLayout android:id="@+id/shata" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:id="@+id

How to achieve automatic width of Button in Android layout

旧巷老猫 提交于 2020-02-24 09:50:40
问题 I have a few Button listed vertically and I need all of them to have the same width, but also to display all text inside. Basically I need width for all of them as a wrapped width of the largest one. Hope I explained it well. Now... I already have one layout that is working on my Samsung Galaxy S2 (4.1.2), but on friend's phone - Samsung GT-N7100 (note2) and android 4.4.2 - it is not working - some text is not displayed in the Button. This is my layout: <RelativeLayout xmlns:android="http:/

How to center the content inside a linear layout?

坚强是说给别人听的谎言 提交于 2020-02-09 18:59:05
问题 I'm trying to center an ImageView inside a LinearLayout horizontally and vertically, but I just can't do it. The main reason why I'm not using a RelativeLayout for that is because I need the layout_weight (my Activity consists of four columns that should be equally divided, and also responsive to different screen widths, each column having an ImageView centered and unstretched). Here is my xml so far: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http:/

How to center the content inside a linear layout?

删除回忆录丶 提交于 2020-02-09 18:58:39
问题 I'm trying to center an ImageView inside a LinearLayout horizontally and vertically, but I just can't do it. The main reason why I'm not using a RelativeLayout for that is because I need the layout_weight (my Activity consists of four columns that should be equally divided, and also responsive to different screen widths, each column having an ImageView centered and unstretched). Here is my xml so far: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http:/

How to achieve equal layout_width and layout_height

一个人想着一个人 提交于 2020-01-25 20:58:06
问题 What I am trying to achieve is to put 4 buttons next to each other, with some margins, and make them square (without supplying fixed sizes) I basically have a wrapper LinearLayout that holds 4 buttons, which I want them to be square shaped. <LinearLayout android:id="@+id/photos_photoWrapper" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:orienation="vertical"> <Button android:id="@+id/photos_photoButton1" android:layout

How do you add a ConstraintLayout to a LinearLayout in a ScrollView that fits the whole screen?

旧巷老猫 提交于 2020-01-25 10:20:09
问题 I want to be able to scroll through a LinearLayout, where each element is a ConstraintLayout that fits the whole screen. I've tried multiple values for layout_height in each Layout but nothing seems to be working. I could hardcode in a layout_height that fits my screen but that is not ideal. Here's what I currently have: <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools=

check to see if a view exists from a layout inflater befor adding another one

…衆ロ難τιáo~ 提交于 2020-01-24 03:54:49
问题 In my android project, I am dynamically adding forms to my linear layout and then destroying them when I am done with a button. However, When I click the "add button" It infinitely adds more forms although I want only one at a time. How can i chec if my linearLayout "accounts" has been added to the view or if it exists in the view at the time? This is the code to add the view. How can I check to see if the view already exists before I add the view? public void showForm(String form){ View view

How can I give my widgets' width a percentage rather than an explicit value?

我们两清 提交于 2020-01-23 09:33:27
问题 Based on how XAML works, I thought I could give my android widgets a percentage value for width. After searching, I found that *theoretically," this is available via the "layout_weight" property. But using this does not produce the desired appearance. Specifically, this xml: <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:padding="5dp"> <Spinner android:id="@+id/spinnerUPCPLU" android:layout_width="0dp" android

How can I give my widgets' width a percentage rather than an explicit value?

旧城冷巷雨未停 提交于 2020-01-23 09:32:35
问题 Based on how XAML works, I thought I could give my android widgets a percentage value for width. After searching, I found that *theoretically," this is available via the "layout_weight" property. But using this does not produce the desired appearance. Specifically, this xml: <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:padding="5dp"> <Spinner android:id="@+id/spinnerUPCPLU" android:layout_width="0dp" android