I have made a listitem, containing a title and a subtitle. Looking to the result, I think it doesn't look really professional. So that's why I'm asking.
The listitem I'm looking for is pretty common (it's used in a lot of apps i.e. Android's default settings menu and it's also shown when you add a listview in the graphical layout editor tab in eclipse).
So my question is: Where can I find a default layout for a listitem with a title and a subtitle?
Resource id is android.R.layout.simple_list_item_2
Upper text line has id android.R.id.text1 and lower one - android.R.id.text2
Layout is located in the <ANDROID_SDK_ROOT>/platforms/<any_api_level>/data/res/layout folder
OR
You can use TwoLineListItem from the default Android controls list(it is located under "Advanced" tab in Eclipse Layout Editor)
OR
You can build your own layout with anything you like(for example LinearLayout with orientation="vertical" and two TextEdits added
So The Best Way Is:- I took out the simple list item 2 and made an layout in my project and with little editing it took the same layout as you may give in android.R.simple_list_item_2
So the code is:-
<?xml version="1.0" encoding="utf-8"?>
<TwoLineListItem xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/listPreferredItemHeight"
android:mode="twoLine"
android:paddingStart="?attr/listPreferredItemPaddingLeft"
android:paddingLeft="?attr/listPreferredItemPaddingLeft"
android:paddingEnd="?attr/listPreferredItemPaddingRight"
android:paddingRight="?attr/listPreferredItemPaddingRight">
<TextView android:id="#+id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:textAppearance="?attr/textAppearanceListItem" />
<TextView android:id="#id/text2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/text1"
android:layout_alignStart="#+id/text1"
android:layout_alignLeft="#+id/text1"
android:textAppearance="?attr/textAppearanceListItemSmall" />
Related
I am a beginner in android development using Java,
I have tried surfing the net but to no avail.
What is name of the library which I can use to make expandable Floating Action Button like the one on the pic below.
Please help.
I was looking at some source codes. I found a best expandable FAB(Float Action Button)
Let me add those source codes.
Add it to build.gradle
implementation 'com.nambimobile.widgets:expandable-fab:1.0.2'
Add following source code to layout
<!-- This is NOT a root view, but should be a child of whatever root view you
choose (CoordinatorLayout, ConstraintLayout, etc) -->
<com.nambimobile.widgets.efab.ExpandableFabLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The next 3 Views will only display in portrait orientation -->
<com.nambimobile.widgets.efab.Overlay
android:layout_width="match_parent"
android:layout_height="match_parent"
app:overlay_orientation="portrait"/>
<com.nambimobile.widgets.efab.ExpandableFab
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginBottom="#dimen/ui_margin_medium"
android:layout_marginEnd="#dimen/ui_margin_medium"
android:layout_marginRight="#dimen/ui_margin_medium"
app:efab_orientation="portrait"/>
<com.nambimobile.widgets.efab.FabOption
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:fab_orientation="portrait"
app:label_text="Portrait Option 1"
android:onClick="onClickPortraitOption1"/>
<!-- The next 3 Views will only display in landscape orientation -->
<com.nambimobile.widgets.efab.Overlay
android:layout_width="match_parent"
android:layout_height="match_parent"
app:overlay_orientation="landscape"/>
<com.nambimobile.widgets.efab.ExpandableFab
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginBottom="#dimen/ui_margin_medium"
android:layout_marginEnd="#dimen/ui_margin_medium"
android:layout_marginRight="#dimen/ui_margin_medium"
app:efab_orientation="landscape"/>
<com.nambimobile.widgets.efab.FabOption
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:fab_orientation="landscape"
app:label_text="Landscape Option 1"
android:onClick="onClickLandscapeOption1"/>
</com.nambimobile.widgets.efab.ExpandableFabLayout>
Then, you can use those FAB as you use on button in Java file.
Let me add that link
I'm currently making an app for Android devices and I would like to know how can I change the way I display the fragments in differents display sizes (ex. Tablet).
At this point I have an activity for all my fragments and this causes me to replace the fragments when I change page but for tablets I would like to display 2 fragments inside that activity.
I've created a layout-large version for my main activity:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".PaginaInicial"
tools:showIn="#layout/app_bar_pagina_inicial">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
class="pt.ipp.estg.schoolhelperapp.apontamento.ListaApontFragment"
android:id="#+id/a_fragment"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent" />
<fragment
class="pt.ipp.estg.schoolhelperapp.apontamento.VerApontFragment"
android:id="#+id/b_fragment"
android:layout_weight="2"
android:layout_width="0dp"
android:layout_height="match_parent" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
The fragment container is inside layout-small version of the main activity.
One of the fragments displays a list of items (#+id/a_fragment) and the other one displays the information of one specific item that I previously selected (#+id/b_fragment).
For further details refer to this document: https://developer.android.com/training/multiscreen/screensizes
Create a default alias resource value file in res/values/refs.xml and place the following code inside it. This value will refer to your layout file that has only one fragment.
<resources>
<item name="activity_masterdetail" type="layout">#layout/layout_with_single_fragment</item>
</resources>
Now need to create an alternative resource so that the activity_masterdetail alias will point to layout_with_two_fragment.xml on larger devices.
Create a new file with same name refs.xml but with resource qualifiers for Smallest Screen Width under Available qualifiers. Use smallest dimension of 600dp or more (sw600dp qualifier)
<resources>
<item name="activity_masterdetail" type="layout">#layout/layout_with_two_fragment</item>
</resources>
Your goal here is to have logic that works like this:
For devices that are under a specified size i.e mobile phones, use layout_with_single_fragment.xml.
For devices that are over a specified size, use layout_with_two_fragment.xml.
Now in your man activity which shows a list, use setContentView(R.layout.activity_masterDetail) i.e the name of referenced layout
If this code will run on mobile phones, normal refs.xml file will be referenced by activity_masterDetailbut if this code runs on a tablet, resource qualified refs.xml file will be used.
In your activity logic, where you want to show master and detail layout on the same screen on tables but open another activity on phones, use the following logic inside onClick() of your list items
if (findViewById(R.id.a_fragment) == null) {
Intent intent = A_Activity.newIntent(this, listItem.getId());
startActivity(intent);
} else {
Fragment newDetail = B_Fragment.newInstance(list_item.getId());
getSupportFragmentManager().beginTransaction()
.replace(R.id.b_fragment, newDetail)
.commit();
}
You should take a look at this before link it should help you understand for sure more about supporting different screen sizes.
And here is an example that you can try.
I am here because I am trying to set programmatically the layout_below parameter of some cardViews without success.
These cardViews are located inside a PercentRelativeLayout (I do not know if it is relevant but these cardviews have been added programmatically too).
I show you the code to make it clear.
...
<android.support.percent.PercentRelativeLayout
android:id="#+id/prl"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
xmlns:percent="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/cv0"
android:layout_width="match_parent"
percent:layout_heightPercent="65%"
percent:layout_marginTopPercent="2%"
percent:layout_marginLeftPercent="2%"
percent:layout_marginRightPercent="2%"
card_view:cardCornerRadius="2dp"
card_view:cardElevation="4dp">
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
xmlns:percent="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/cv1"
// here I would like to add android:layout_below="#+id/cv0"
android:layout_width="match_parent"
percent:layout_heightPercent="65%"
percent:layout_marginTopPercent="2%"
percent:layout_marginLeftPercent="2%"
percent:layout_marginRightPercent="2%"
card_view:cardCornerRadius="2dp"
card_view:cardElevation="4dp">
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
xmlns:percent="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/cv2"
// here I would like to add android:layout_below="#+id/cv1"
android:layout_width="match_parent"
percent:layout_heightPercent="65%"
percent:layout_marginTopPercent="2%"
percent:layout_marginLeftPercent="2%"
percent:layout_marginRightPercent="2%"
card_view:cardCornerRadius="2dp"
card_view:cardElevation="4dp">
</android.support.v7.widget.CardView>
</android.support.percent.PercentRelativeLayout>
...
I tried to do something like this in my Java code but without success.
PercentRelativeLayout prl = (PercentRelativeLayout) view.findViewById(R.id.prl);
CardView cv = (CardView) LayoutInflater.from(getActivity()).inflate(R.layout.cv_block, prl, false);
cv.setId(currentId++);
prl.addView(cv);
cv = (CardView) LayoutInflater.from(getActivity()).inflate(R.layout.cv_block, prl, false);
cv.setId(currentId++);
RelativeLayout.LayoutParams cv_lp = (RelativeLayout.LayoutParams) cv.getLayoutParams();
cv_lp.addRule(RelativeLayout.BELOW,currentId-2);
/* I have also tried to call cv.requestLayout() but nothing changed */
prl.addView(cv);
As you can see, I am trying to generate cardviews and insert them one below the other.
Thanks in advance for your help.
PercentRelativeLayout is depreciated, so you are encouraged to use other type of layout.
This class was deprecated in API level 26.1.0.
consider using ConstraintLayout and associated layouts instead. The following shows how to replicate the functionality of percentage layouts with a ConstraintLayout. The Guidelines are used to define each percentage break point, and then a Button view is stretched to fill the gap:
ConstraintLayout gives lots of opportunities.
More about PercentRelativeLayout deprecation here.
More about ConstraintLayout and how to use it here or video tutorial.
Suppose I have a layout file structured like this:
<LinearLayout android:id="#+id/main" android:orientation="vertical" android:animateLayoutChanges="true">
<EditText>
<TextView android:id="#+id/header1">
<LinearLayout android:id="#+id/insertionPoint" android:orientation="vertical" android:animateLayoutChanges="true">
</LinearLayout>
<TextView android:id="#+id/header2">
</LinearLayout>
I want to dynamically add text fields to the Layout insertionPoint and I would like to see an animation of the elements below it (in this case, header2) sliding down.
Using android:animateLayoutChanges only animates the elements in the layout insertionPoint, so there is no animation for header2. What should I do?
Just to be more clear: what I would like to do here is something like the animations that we can see in the People app in ICS when we add more fields, like telephone numbers, to a contact.
Thank you!
API 16 added the LayoutTransition.CHANGING animation type, however it is disabled by default.
To enable:
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.main);
linearLayout.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
Nice DevBytes video: https://www.youtube.com/watch?v=55wLsaWpQ4g
I have used fragments to define a simple splitview, in the right site i used a layout containing videoview the xml code is:
<?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="vertical" >
<VideoView
android:id="#+id/tvT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
and in the left site in another fragment layout I have defined some buttons to play different videos, The program is running well in emulators, but when I run it on device, the videoview overlapped the whole area and creates a horrible look, what should I do?
You need to post more of your code if you can; what you have posted isn't really enough for people to help you. [Edit: Darn, I thought this was trivial enough to be automatically moved to a comment on the original question :-\ ]
May you could try with "fill_parent" because the video could be to big and uses the hole display:
<VideoView
android:id="#+id/tvT"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
If you can it would be good if you post some code how you setup your fragments.