Button not appearing in my Linear Layout - java

I have a button inside of a LinearLayout that is oriented vertically. Not sure why the button doesn't show up?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical">
<com.commonsware.cwac.tlv.TouchListView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tlv="http://schemas.android.com/apk/res/org.stocktwits.activity"
android:id="#android:id/list"
android:layout_width="fill_parent"
android:drawSelectorOnTop="false"
tlv:normal_height="64dip"
tlv:grabber="#+id/icon"
tlv:remove_mode="slideRight"
android:layout_height="wrap_content"/>
<Button android:text="Button" android:id="#+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>

android:height="wrap_content" has no meaning for vertically-scrollable widgets like ListView. Use android:layout_weight with your LinearLayout or a RelativeLayout to achieve whatever look you are trying to achieve.

Try adding this to your LinearLayout:
android:layout_width="fill_parent"
android:layout_height="fill_parent"
I'm guessing the layout is just not showing?

Related

ExpandableListView groupItem inside Fragment+ViewPager cuts off half of the item horizontally

I have a ExpandableListView inside of a fragment inside of a ViewPager.
The issue is that the group item is being cut in half horizontally, show below in the image.
I have the same exact code for the ExpandableListView elsewhere in the application, but inside of an activity, and it works fine?
XML layout for the group item:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:orientation="vertical"
>
<TextView
android:id="#+id/lbl_exercise_group"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft"
android:textSize="20dp"
android:textColor="#color/white"
android:background="#color/material_blue_500"
/>
</LinearLayout>
I think the layout_with from The TextView should be match_parent for the full size.
The issue was: in my ExpandableListView XML definition layout_width was set to wrap_content, it needed to be fill_parent
I changed:
<ExpandableListView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/exList_exercises"
android:clickable="true"
/>
to
<ExpandableListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/exList_exercises"
android:clickable="true"
/>

Make EditText clickable

Good evening,
i have the following layout and i would like to make the Edit Text clickable everywhere. Also if layout_height is set to match_parent, the Edit Text clickable area works like wrap_content.
This is the layout.
<?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"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:focusable="true"
android:focusableInTouchMode="true">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar"/>
<RelativeLayout
android:id="#+id/relative"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/toolbar">
<TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="20dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingRight="20dp">
<EditText
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</TextInputLayout>
</RelativeLayout>
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/relative">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp">
<EditText
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="#string/note_content"
android:background="#null"
android:gravity="top"/>
</TextInputLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
How can i make the Edit Text clickable everywhere in the Relative Layout inside the Scroll View?
While I don't understand why you are wanting to do this, you could make an button with the invisible property set to true, that covers the entire layout. Then respond when user touches this invisible button.
You respond by using the EditText method called setOnEditorActionListener()
See the info on this page with the heading "Responding to action button events":
http://developer.android.com/guide/topics/ui/controls/text.html
In a scrollView you can't fill the entire view until there is content here, you are asking to make the EditText Fill the whole parent space left apart from the TextView so that you can click any part of the layout to focus on the EditText. Except you give the EditText a layout_height it will remain wrap since the layout is in the RelativeLayout' which is a child for of theScrollView`.

How to fix the position of Button in Android

I am working on a project in which I need to dynamically add TextView and Spinner as well through the program. I was able to add these two things dynamically from my program successfull.
Below is the XML layout I have used for that.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/llayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
android:layout_width="100px"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal|center"
android:gravity="center_vertical|center_horizontal"
android:text="Save" />
</LinearLayout>
</ScrollView>
Problem Statement:-
So what I want is- All the TextView and Spinner should get shown firstly then in the last Button should get shown.
But what is happening currently Save Button gets shown at the Top and then all the other TextView and Spinner gets shown.
How can I make sure, that Button comes at the bottom of screen.
Below is the screenshot from which you can figure out the problem. I want to show the Save button at the bottom of screen.
Or you can create a button like this in the code and added to your layout after adding all the spinners and textviews like below, you will have to remove the declaration of the button from your xml:
Button button = new Button(this) ///this is a context object
button.setWidth(100);
button.setText("Save");
layout.addView(button);
You can dynamically create the layout and add the button to that layout and then add this layout to the Super layout
Or what you can do is Declare a new xml file in the res/layout/savebutton_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:id="#+id/lLayoutBT"
>
<Button
android:id="#+id/saveBT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/save" />
</LinearLayout>
Now in your code you will have to find this layout containing the button and then add this layout to your main layout (just like you were adding your button)
For example
LinearLayout buttonLayout =(LinearLayout) view.findViewById(R.id.lLayoutBT);
views.add(buttonLayout);
If you use a RelativeLayout (instead of a LinearLayout) you have access to properties like:
<Button
android:id="#+id/button1"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
...
</Button>
If you change your LinearLayout to a RelativeLayout then add this in your Button
<Button
...
android:layout_alignParentBottom="true"/>
it should give you what you want. I use RelativeLayout instead of LinearLayout as often as possible anymore because in most instances, it is the more flexible and efficient. They take a little more time to get used to but are definitely worth taking the time to understand and implement
Edit
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/llayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/button1"
android:layout_width="100px"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"/>
android:text="Save" />
</RelativeLayout>
</ScrollView>
Something like that should work. You may have to play with it a little to get exactly what you want but that should get you there.

Overwriting paddingLeft in a LinearLayout on Android

i am currently making one android application, i moded title bar, so all content for title bar is holded in window_title.xml where i have LinearLayout set: paddingLeft="5dip" . And now i need to load one imageView on the right side of this titleBar how i am able to some kind of overwrite this paddingLeft i cant delete it as it required for text and image on the left but i need it on right too...
Here is current xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:gravity="center_vertical"
android:paddingLeft="5dip"
android:background="#222222">
<ImageView
android:id="#+id/header"
android:src="#drawable/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:text="TextTexast"
android:textSize="10pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="5dip"
android:textColor="#F7F7F7"
/>
</LinearLayout>
If I understand your question correctly, you're looking to apply some padding to an ImageView that you display to the right of the titlebar TextView. You can use android:paddingRight in your root LinearLayout like this:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:gravity="center_vertical"
android:paddingLeft="5dip"
android:paddingRight="5dip
android:background="#222222">
Alternatively, you can specify the android:paddingRight attribute in the ImageView that you want to align to the right.
To move the grey figure to the right just set android:layout_gravity for that to "right".

Making android listview layout scrollable

I have an xml file that has the layout in ASCII form:
---------------
| ImageView
--------------
| TextView
--------------
| List...
--------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res/com.some.app"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="#+id/MovieCover"
android:layout_width="100dip"
android:layout_height="100dip"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:padding="10dp"
android:id="#+id/TextHeader"
android:background="#000000">
</TextView>
<ListView android:id="#+id/ListView02" android:layout_height="wrap_content"
android:layout_width="fill_parent">
</ListView>
</LinearLayout>
I'm having a problem displaying the layout when my ImageView and TextView takes up more than 3/4 of the screen. How do I make ImageView and TextView scrollable with the ListView that is being displayed? At this point of time, only the ListView to be scrolled and I want the entire layout to be scrollable as though they are one page on its own.
How can I do that?
You can use <ScrollView> as your layout container
something along the line of
<ScrollView>
<LinearLayout>
// your layout here
</LinearLayout>
</ScrollView>
the reason why we need the LinearLayout inside is that ScrollView can only have one direct child
Butter to use two LinearLayout with layoutweight="1" and put ScrollView in one and listview in other
<LinearLayout android:layout_weight="1"
android:layout_height="fill_parent" android:layout_width="fill_parent">
<ScrollView android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- scroll view content -->
</LinearLayout>
</ScrollView>
</LinearLayout>
<LinearLayout android:layout_weight="1"
android:layout_height="fill_parent" android:layout_width="fill_parent">
<ListView android:id="#+id/ListView02" android:layout_height="wrap_content"
android:layout_width="fill_parent">
</ListView>
</LinearLayout>
ListView has addtoHeader and addtoFooter function. Make a separate layout and add it into header of ListView . In your case make a relative layout of imageview and textview and add it to the header of listview. The entire page will start scrolling.
How about putting the ImageView and TextView in a layout and putting this layout inside a ScrollView.?

Categories

Resources