I'm updating an app someone made a couple of years back and I'm trying to add a footer visible all the time. I'm working on adding it on one of my activity, but here's the result:
Here is my .xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<!-- Footer -->
<include layout="#layout/footer"/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/footer">
<TextView
android:id="#+id/list_items"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="22dp" >
</TextView>
</RelativeLayout>
And here's my line that calls it
setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, R.id.list_items, mRegions));
Thanks in advance!
Related
I have an app with a MainActivity, which launch a SecondActivity where I have a recyclerView with lots of items, and each item contains an image. When calling the startActivity() method to launch the SecondActivity, I observe some delay because all items are loaded before the secondActivity start.
I'm trying to load only items that are displayed on screen, and load the rest of them only when the user scrolls, step by step, so there is no latency anymore when calling the SecondActivity.
Here is my code :
mainActivity.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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"
android:background="#color/mainLayoutBackground"
tools:context=".main.MainActivity">
<!-- some stuff -->
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:listitem="#layout/recyclerview_item"
android:nestedScrollingEnabled="false"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
recyclerview_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#color/mainLayoutBackground"
android:orientation="vertical"
android:layout_marginBottom="10dp">
<androidx.cardview.widget.CardView
android:id="#+id/first_card_view_halo"
android:layout_width="70dp"
android:layout_height="70dp"
app:cardBackgroundColor="#color/blue"
app:cardCornerRadius="150dp"
android:layout_gravity="center"
android:layout_marginBottom="10dp">
<androidx.cardview.widget.CardView
android:id="#+id/second_card_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="2dp"
app:cardCornerRadius="150dp">
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:src="#drawable/img" />
</androidx.cardview.widget.CardView>
</androidx.cardview.widget.CardView>
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="10sp"
android:text="#string/app_name"
android:textAlignment="center"
android:textColor="#android:color/white" />
</LinearLayout>
Then I set the images of each items programmatically with adapter and viewHolder, and I observe a few seconds latency when launching SecondActivity.
How to load only currently displayed items ?
I'm getting data from Firebase Firestore to populate a ListView, and I would like to show a loading animation while the data is being fetched.
The code for layout
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout android:id="#+id/loading"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
xmlns:android="http://schemas.android.com/apk/res/android">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true" />
</RelativeLayout>
<ListView android:id="#+id/list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
xmlns:android="http://schemas.android.com/apk/res/android" />
</FrameLayout>
The code in java
private void finishLoadList(){
RelativeLayout loadingLayout = (RelativeLayout) findViewById(R.id.loading);
ListView listView = (ListView) findViewById(R.id.list_view);
loadingLayout.setVisibility(View.GONE);
listView.setVisibility(View.VISIBLE);
}
Problem I want view-layout like the following photo, on top I want image view, in the middle a text view and bottom list of items. All this I want to be scrollable (black arrow in the picture). in this way, the user for first see image-text-and part of list items, if scroll down, see the list of item.
For the bottom I thought to use listView, but in this way I think I'll have 2 scrollable view (???) and then I want to make the list in 2 columns, and I don't know if it is possible with ListView
Question
I didn't write code, because I want to know what kind of view or somethings else I've to study.
I sketchy something like this, but the result is really horrible
activity_main.xml
<?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"
android:layout_width="match_parent" android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent" android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="200dp"
app:srcCompat="#drawable/nope"
android:id="#+id/imageView4"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true" />
<View
android:id="#+id/centerShim5"
android:layout_height="0dp"
android:layout_width="match_parent"
android:layout_centerInParent="true"
android:visibility="invisible" />
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/list"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:text="TextView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/textView2"
android:textColor="#color/ame_default_cluster_circle_color_medium"
android:textSize="26dp"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
</ScrollView>
I can't use listview in Scrollview, and inspired by the matryoshka I found the solution.
I define xml1 file in which I have only ScrollView and LinearLayout inside
<?xml version="1.0" encoding="utf-8"?>
<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="match_parent"
android:orientation="vertical"
android:id="#+id/linear">
</LinearLayout>
</ScrollView>
after, for each kind of items that I want to add inside, I define another xml2 and after I add element:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/ame_default_cluster_text_color">
<TextView
android:text="TextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="5"
android:textSize="32sp"
android:textColor="#color/ame_default_cluster_circle_shadow_color"
android:id="#+id/text1"
android:textAlignment="center" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="#drawable/nope"
android:id="#+id/photo" />
<TextView
android:text=" "
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:id="#+id/descrtiption"
android:textColor="#color/ame_default_cluster_circle_shadow_color"
android:layout_margin="10sp" />
</LinearLayout>
with code:
layoutInflater = (LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View item_view=layoutInflater.inflate(R.layout.xml1,container,false);
LinearLayout linearLayout=(LinearLayout)item_view.findViewById(R.id.linear);
LayoutInflater inflater= LayoutInflater.from(ctx);
View view1 = inflater.inflate(R.layout.xml2, linearLayout, false);
TextView text1=(TextView)view1.findViewById(R.id.text1);
text1.setText();
ImageView imageview=(ImageView)view1.findViewById(R.id.photo);
and obviously I can define XML for element to add like listview and add it with normal foreach ,Hope this will help someone.
Temperature is the text that needs to be displayed at the bottom and activity_display_message is the 1337 that needs to be displayed at the top.
Add a TextView and use textView.setText(your_string); on it. I'm assuming you are trying to print the text on the LinearLayout currently.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.myapplication.DisplayMessageActivity">
<TextView
android:id="#+id/activity_display_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/temperature"/>
</LinearLayout>
Code,
TextView textView = (TextView) findViewById(R.id.activity_display_message);
textView.setText(your_string);
you can try this
use two text view to show your value and "Temperature" text. you can use RelativeLayout to easily manage show temperature text at bottom.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/activity_display_message"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tempValue"
android:textSize="25sp"
android:gravity="center"
android:text="Value"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Temperature"
android:textSize="25sp"
android:gravity="bottom|center"
android:layout_below="#+id/tempValue"/>
</RelativeLayout>
and inside java write
TextView txtTempValue = (TextView)findViewById(R.id.tempValue);
txtTempValue.setText(your_temp_value);
I have a ListActivity that I'm trying to inflate a Button from this layout file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="#+id/add_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/add_prop"
android:layout_alignParentBottom="true"
/>
</LinearLayout>
Using this code:
View footer = getLayoutInflater().inflate(R.layout.footer, null);
ListView listView = getListView();
listView.setTextFilterEnabled(true);
listView.addFooterView(footer, null, false);
The problem is that since the list isn't so big that takes the entire screen (at least I think this is why) the button stays at the end of the list instead of sticking to the bottom because of the android:layout_alignParentBottom="true" property. What should I do to make it stick at the bottom?
You have to create a new layout file with this code:
<?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" >
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/add_button" />
<Button
android:id="#+id/add_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/add_prop"
android:layout_alignParentBottom="true" />
</RelativeLayout >
Then set it as content view of your Activity using setContentView()