I have two Linear layouts in a xml file, one contains a textview follwed by list view. The next layout should be shown below the list view, which shows the description of selected item in listview as textview. Is this possible ? Below code doesn't show TextView01. In what other way i can do it, if it's not possible by this simple way?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF88334C"
android:orientation="vertical"
>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
android:text="#string/hello_world"
android:textColor="#FFAABBFF" />
<ListView
android:id="#android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="48dp" >
</ListView>
<LinearLayout
android:id="#+id/LinearLayou"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF88334C"
android:orientation="vertical"
>
<TextView
android:id="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/byebye_world"
android:textColor="#FFAEEEFF" />
</LinearLayout>
</LinearLayout>
try below code:-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF88334C"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="hello_world"
android:textColor="#FFAABBFF" />
<ListView
android:id="#android:id/list"
android:layout_below="#+id/textView1"
anndroi:layout_above="#+id/LinearLayou"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
</ListView>
<LinearLayout
android:id="#+id/LinearLayou"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FF88334C"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:orientation="vertical" >
<TextView
android:id="#+id/TextView01"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="byebye_world"
android:textColor="#FFAEEEFF" />
</LinearLayout>
</RelativeLayout>
you need to use layout_weight attribute for this. try this layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF88334C"
android:orientation="vertical"
>
<LinearLayout
android:id="#+id/LinearLayou"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FF88334C"
android:orientation="vertical"
android:layout_weight="1"
>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
android:text="#string/hello_world"
android:textColor="#FFAABBFF" />
<ListView
android:id="#android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="48dp" >
</ListView>
</LinearLayout>
<LinearLayout
android:id="#+id/LinearLayou"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FF88334C"
android:orientation="vertical"
android:layout_weight="2"
>
<TextView
android:id="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/byebye_world"
android:textColor="#FFAEEEFF" />
</LinearLayout>
</LinearLayout>
Related
I'm trying to position a few Cardviews below eachother in a RelativeLayout, but it isn't working out so far. The cardviews are all on top of eachother, but layout_below is set for all of them. It's pretty strange, because it did work in the past if I recall correctly.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com"
xmlns:android.support.v7.cardview="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context="something.something.fragments.RosterFragment"
android:id="#+id/relativeLayout"
android:background="#color/white"
tools:ignore="MergeRootFrame">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="false"
android:id="#+id/rosterContainer0">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:id="#+id/cardViewMonday"
android:longClickable="true"
style="#style/InformationCard">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/TitleLightBackground"
android:text="Maandag"
android:id="#+id/dateMonday" />
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/rosterListViewMonday"
android:background="#color/white">
</ListView>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:id="#+id/cardViewTuesday"
android:longClickable="true"
style="#style/InformationCard"
android:layout_below="#+id/cardViewMonday">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/TitleLightBackground"
android:text="Dinsdag"
android:id="#+id/dateTuesday" />
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/rosterListViewTuesday"
android:background="#color/white">
</ListView>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:id="#+id/cardViewWednesday"
android:longClickable="true"
style="#style/InformationCard"
android:layout_below="#+id/cardViewTuesday">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/TitleLightBackground"
android:text="Maandag"
android:id="#+id/dateWednesday" />
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/rosterListViewWednesday"
android:layout_below="#+id/dateWednesday"
android:background="#color/white">
</ListView>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:id="#+id/cardViewThursday"
android:longClickable="true"
style="#style/InformationCard"
android:layout_below="#+id/cardViewWednesday">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/TitleLightBackground"
android:text="Maandag"
android:id="#+id/dateThursday" />
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/rosterListViewThursday"
android:layout_below="#+id/dateThursday"
android:background="#color/white">
</ListView>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:id="#+id/cardViewFriday"
android:longClickable="true"
style="#style/InformationCard"
android:layout_below="#+id/cardViewThursday">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/TitleLightBackground"
android:text="Maandag"
android:id="#+id/dateFriday" />
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/rosterListViewFriday"
android:layout_below="#+id/dateFriday"
android:background="#color/white">
</ListView>
</android.support.v7.widget.CardView>
</RelativeLayout>
</ScrollView>
Watch out when you copy - paste code.
All your cards have the attribute android:layout_alignParentTop="true"
The below XML contains an EditText control. As soon as I touch it, the softkeyboard appears but the HorizontalScrollView scrolls to the right so I cannot see the EditText!
Can somebody please tell me what is wrong with the below XML and why it is doing this?
Please excuse hardcoded widths - this is only a test bit of code for sanity checking.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<HorizontalScrollView
android:id="#+id/testScrollView"
android:layout_width="1280dp"
android:layout_height="match_parent"
android:scrollbars="horizontal"
android:background="#00FF00">
<LinearLayout
android:id="#+id/layout"
android:layout_width="2560dp"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/mLeftBaseLinearLayout"
android:layout_width="1280dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#FF0000">
<EditText
android:id="#+id/mEditText"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#BBBBBB"
android:gravity="center"
android:text="EditText"
android:textColor="#FFFF00"
android:textSize="30dp"
android:singleLine="true"
android:clickable="true"
android:editable="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:inputType="text"/>
<ListView
android:id="#+id/mListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#80FFFFFF" >
</ListView>
</LinearLayout>
<LinearLayout
android:id="#+id/linLayout"
android:layout_width="1280dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#00FF00">
<Button
android:layout_width="600dp"
android:layout_height="wrap_content"
android:text="Button1" />
<Button
android:layout_width="600dp"
android:layout_height="wrap_content"
android:text="Button2" />
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>
</FrameLayout>
My tablet is running Android 4.2.1
Ok, I have been looking at your layout and made a few changes and it looks ok on my computer.
Firstly, mEditText is unnecessary and avoidable. If you want a header for mListView
yourListView.addHeaderView(View v, Object data, boolean isSelectable);
This is what I did:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<HorizontalScrollView
android:id="#+id/testScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00FF00"
android:scrollbars="horizontal" >
<LinearLayout
android:id="#+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/mLeftBaseLinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF0000"
android:orientation="vertical" >
<EditText
android:id="#+id/mEditText"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#BBBBBB"
android:clickable="true"
android:editable="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="center"
android:inputType="text"
android:singleLine="true"
android:text="EditText"
android:textColor="#FFFF00"
android:textSize="30dp" />
<ListView
android:id="#+id/mListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#80FFFFFF" >
</ListView>
</LinearLayout>
<LinearLayout
android:id="#+id/linLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00FF00"
android:orientation="vertical" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button2" />
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
If this does not work we need to look at your code.
I found my solution - override scrollTo() and do absolutely nothing.
I have main RelativeLayout layout file. I have scrollview and two buttons and listview inside this scrollview.I have one problem , when i run program it show's only one item in listview.my problem is xml file. How i can change my problem?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ScrollView
android:id="#+id/scrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<RelativeLayout
android:id="#+id/layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:background="#5f2585" >
<Button
android:id="#+id/studia"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#drawable/n_button"
android:text="სტუდია"
android:textColor="#ffffff" />
<ListView
android:id="#+id/menu_listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/studia"
android:divider="#null"
>
</ListView>
<Button
android:id="#+id/gadacema"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_below="#+id/menu_listview"
android:background="#drawable/n_button"
android:text="გადაცემა"
android:textColor="#ffffff" />
</RelativeLayout>
in programmatically everything is ok(if i deleted scrollview,then i can show all values,but i cannot show button witch is a below in listview
What is wrong in my xml file. How can i solve this problem?
Please try this.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<RelativeLayout
android:id="#+id/layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:background="#5f2585" >
<Button
android:id="#+id/studia"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#drawable/n_button"
android:text="სტუდია"
android:textColor="#ffffff" />
<ListView
android:id="#+id/menu_listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/studia"
android:divider="#null"
>
</ListView>
<Button
android:id="#+id/gadacema"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_below="#+id/menu_listview"
android:background="#drawable/n_button"
android:text="გადაცემა"
android:textColor="#ffffff" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
Try this:-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<Button
android:id="#+id/studia"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#drawable/n_button"
android:text="სტუდია"
android:textColor="#ffffff" />
<ListView
android:id="#+id/menu_listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/studia"
android:divider="#null"/>
<Button
android:id="#+id/gadacema"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_below="#+id/menu_listview"
android:background="#drawable/n_button"
android:text="გადაცემა"
android:textColor="#ffffff" />
</RelativeLayout>
I have a scroll view in my activity view,in this layout i will add dynamic content in 'ucontent','pcontent' by inflating another layout in a loop( the number of inflated layout changes with time).I need to scroll the scrollview sv so that the tiltle with 'titlep' comes in top when i click 'titlep'.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/sv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#232323"
android:scrollbars="none" >
<LinearLayout
android:id="#+id/main"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="#232323"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/titleu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#D84A49"
android:orientation="horizontal"
android:paddingBottom="7dp"
android:paddingTop="7dp" >
<ImageView
android:id="#+id/toggleu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="2dp"
android:src="#drawable/toggleu" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="title1....."
android:textColor="#ffffff" />
</LinearLayout>
<LinearLayout
android:id="#+id/ucontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:id="#+id/titlep"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginBottom="0dp"
android:layout_marginTop="5dp"
android:background="#D84A49"
android:orientation="horizontal"
android:paddingBottom="7dp"
android:paddingTop="7dp" >
<ImageView
android:id="#+id/togglep"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="2dp"
android:src="#drawable/toggleu" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight=".1"
android:text="title2...."
android:textColor="#ffffff" />
</LinearLayout>
<LinearLayout
android:id="#+id/pcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
How can i do that in my code or in xml?
Have a look at this:
Views
use isFocusable(true)
and on the onClick use requestFocus()
I'm using TabHost and inside of one tab, I inserted ListView. I set all height's to fill_parent. But it doesn't show full list, but only part of it. What to do to make tab contents fill screen by height?
<?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
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/bkg"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="7dp"
android:layout_marginRight="7dp"
android:layout_marginTop="7dp"
android:background="#drawable/gradientrounded"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:src="#drawable/taxisign" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/taxiprofiletitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_weight="0.9"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000" />
<Button
android:id="#+id/phonenumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="5dp"
android:background="#drawable/button"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:text="Button"
android:textColor="#ffffff" />
</LinearLayout>
<ProgressBar
android:id="#+id/loadFeedbacks"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center"
android:visibility="invisible" />
</LinearLayout>
<TabHost
android:id="#android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFF0000" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:background="#FF000000"
android:layout_height="wrap_content" >
<TextView
android:tag="tab0"
android:text="Инфо"
android:background="#android:drawable/btn_star_big_on"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<TextView
android:tag="tab1"
android:text="Отзывы"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<TextView
android:tag="tab2"
android:text="Тарифы"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</TabWidget>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" >
<LinearLayout
android:id="#+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/profile_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Info" />
</LinearLayout>
<LinearLayout
android:id="#+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView android:text="Добавить"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</TextView>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<ListView
android:id="#+id/reviewslist"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
<LinearLayout
android:id="#+id/tab3"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="#+id/tariffslist"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" >
</ListView>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
</ScrollView>
On your very first LinearLayout change the layout_height="match_parent". Also, fill_parent has been deprecated since API 8 and replaced with match_parent so that is what you should be using instead.
You have used wrap content for your listView height. You should always use height as match_parent/fill_parent. I guess your problem is here
<ListView
android:id="#+id/reviewslist"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
change it to:
<ListView
android:id="#+id/reviewslist"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
Adding to that, this layout seems to be innefcient. Listviews inside scrollviews are not recommended.
It does seem while quickly viewing the XML file that the parent of your TabHost (LinearLayout) is 'wrap_content' so I am not sure that you are getting all the parents. I do desire a better UI interface for building visuals through Eclipse. Not too happy to work out issues like this when they come up. And they can come up frequently. Usually it involves some trial and error to get things looking the way I want.
Scroll Layout was unnecessary, removing it, made code to work