I'm using InfoWindow to render any information for marker.
In Android, we can define shadow with elevation.
But the shadow defined by elevation is not rendered for InfoWindow.
The layout of infoWindow is like this
<RelativeLayout
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="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/background"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:paddingTop="6dp"
android:paddingBottom="6dp"
android:elevation="4dp"
>
<TextView
android:id="#+id/main_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:textSize="14sp"
android:textStyle="bold"
tools:text="main text"
/>
<TextView
android:id="#+id/sub_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/main_text"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:textSize="11sp"
tools:text="sub text"/>
</RelativeLayout>
Shape is like this
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="500dp"/>
<solid android:color="#color/white"/>
</shape>
Code snippet is like this
googleMap?.setInfoWindowAdapter(object: GoogleMap.InfoWindowAdapter {
override fun getInfoContents(marker: Marker?): View? {
return null
}
override fun getInfoWindow(marker: Marker?): View? {
return layoutInflater.inflate(R.layout.map_info_window, null)
}
})
Related
I am trying to display the entire content of each item in ListView. I read other posts (1)(2), but none of them worked.
Things I tried so far:
(1) I added android:minHeight="?android:attr/listPreferredItemHeight" to TextView
(2) Just in case, I added android:minHeight="?android:attr/listPreferredItemHeight" to ListView
(3) I added android:height=wrap_content to TextView
(4) I added android:height=wrap_content to to ListView
(5) I added (1) and (3)
(6) I added (2) and (4)
(7) I added convertView.setMinimumHeight(100); in my java file
Here is my file with ListView:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
tools:context=".FragmentNotes"
android:theme="#style/FontStyle"
android:id="#+id/fragment_note_id">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorPrimary"
android:orientation="vertical">
<TextView
android:id="#+id/white_background_round"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:background="#drawable/white_background_round" />
<RelativeLayout
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/white_background_round"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp">
<TextView
android:id="#+id/title_string"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Notes"
android:textColor="#color/colorPrimary"
android:textSize="45sp"
android:textStyle="bold"
android:layout_marginBottom="10sp"/>
<ImageView
android:id="#+id/title_image"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_alignTop="#+id/title_string"
android:layout_alignBottom="#+id/title_string"
android:layout_marginLeft="20dp"
android:layout_toEndOf="#+id/title_string"
android:background="#drawable/ic_note_english" />
</RelativeLayout>
<ImageView
android:id="#+id/button_background"
android:layout_width="wrap_content"
android:layout_marginTop="10dp"
android:layout_height="30dp"
android:layout_alignStart="#+id/white_background_round"
android:layout_alignEnd="#+id/white_background_round"
android:layout_marginRight="60dp"
android:layout_marginLeft="60dp"
android:layout_below="#+id/title"
android:background="#drawable/light_background_round_english" />
<Button
android:id="#+id/btn_my_notes"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignTop="#+id/button_background"
android:layout_alignStart="#+id/button_background"
android:layout_alignBottom="#+id/button_background"
android:layout_toStartOf="#+id/centerline"
android:text="My Notes"
android:textColor="#color/colorPrimary"
android:textStyle="bold"
android:background="#android:color/transparent"
android:elevation="10dp"/>
<Button
android:id="#+id/btn_all_notes"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignTop="#+id/button_background"
android:layout_alignEnd="#+id/button_background"
android:layout_alignBottom="#+id/button_background"
android:layout_toEndOf="#+id/centerline"
android:text="All Notes"
android:textColor="#color/colorPrimary"
android:textStyle="bold"
android:background="#android:color/transparent"
android:elevation="10dp"/>
<TextView
android:id="#+id/centerline"
android:layout_width="1dp"
android:layout_height="10dp"
android:layout_alignBottom="#+id/button_background"
android:layout_centerHorizontal="true"
android:layout_below="#+id/title"
android:background="#color/colorPrimary"
android:layout_margin="5dp"
android:layout_alignTop="#+id/button_background"/>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/white_background_round"
android:layout_alignLeft="#id/white_background_round"
android:layout_alignBottom="#id/white_background_round"
android:layout_below="#+id/button_background"
android:layout_margin="10sp"
android:id="#+id/list_view" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:layout_margin="20dp"
android:layout_alignBottom="#id/white_background_round"
android:layout_alignRight="#id/white_background_round"
android:src="#drawable/ic_add_white"/>
</RelativeLayout>
</FrameLayout>
And here is my file with TextView:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/listview_item_text"
android:textColor="#color/colorPrimary"
android:text="1) When anyone brings a grain offering to the Lord, their offering is to be of the finest flour. They are to pour olive oil on it, put incense on it"
android:textSize="20dp"
android:paddingLeft="20sp"
android:paddingRight="20sp"
android:paddingTop="10sp"
android:paddingBottom="10sp"
android:textStyle="bold"
android:lineSpacingMultiplier="1.5"
android:layout_width="fill_parent"
android:singleLine="true"
android:layout_height="wrap_content"/>
Any help will be greatly appreciated.
Just in case anyone needs this answer, I found that the problem was TextView's line android:singleLine="true". I removed the line, and now I can see all contents for each item in ListView.
My Firebase app uses Google signin as well as non-Gmail signin. I've seen the little red "Sign in with email" button here, but I couldn't find a layout that shows how to code it. My login activity looks like the following:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
// Views
findViewById(R.id.signInButton).setOnClickListener(this);
findViewById(R.id.emailSignInButton).setOnClickListener(this);
// Configure Google Sign In
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();
mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
}
and here's activity_login:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:gravity="center_horizontal"
android:orientation="vertical">
<ImageView
android:id="#+id/app_logo"
android:layout_alignParentTop="true"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:src="#drawable/logo"/>
<TextView
android:id="#+id/welcome"
android:layout_below="#+id/app_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:layout_centerHorizontal="true"
android:text="#string/welcome"
android:visibility="invisible"
android:textSize="20sp"
android:textStyle="bold" />
<ProgressBar
android:id="#+id/progressBar"
style="#style/Widget.AppCompat.ProgressBar"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:visibility="invisible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<com.google.android.gms.common.SignInButton
android:id="#+id/signInButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"
android:visibility="visible" />
<Button
android:id="#+id/emailSignInButton"
android:layout_below="#+id/signInButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/email_signin"
android:layout_centerInParent="true" />
</RelativeLayout>
</LinearLayout>
I want to replace the Button tag with something that will render the same button one gets using AuthUI.IdpConfig.EmailBuilder().build(). I don't want to use the approach given on the page I referenced above as that not only violates best principles (declare the UI in XML rather than coding it inline) but also would necessitate major changes to code that's already working.
Thanks to Frank van Puffelen's suggestion, I found the button I needed:
<com.firebase.ui.auth.util.ui.SupportVectorDrawablesButton
android:id="#+id/email_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/FirebaseUI.Button.AccountChooser.EmailButton"
android:text="#string/fui_sign_in_with_email"
tools:ignore="UnusedIds" /> <!-- Used in tests -->
Suppose i have a horizontal GuideLine at 30% of parent and a View (suppose a Button) how can i make that view be centered on the guideline?
Like this:
Update:
The view i'm using here has height based on ratio, and soltuion on answers doesnt works.
Here is current layout:
<?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"
tools:context=".MainActivity">
<ImageView
android:id="#+id/imgLogo"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="#id/guideline_30"
app:layout_constraintDimensionRatio="H,1:1"
app:layout_constraintEnd_toStartOf="#+id/guidelineV_75"
app:layout_constraintStart_toEndOf="#+id/guidelineV_25"
app:layout_constraintTop_toTopOf="#+id/guideline_30"
app:srcCompat="#drawable/ic_launcher_background" />
<android.support.constraint.Guideline
android:id="#+id/guideline_30"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.3" />
<android.support.constraint.Guideline
android:id="#+id/guidelineV_25"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.25" />
<android.support.constraint.Guideline
android:id="#+id/guidelineV_75"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.75" />
</android.support.constraint.ConstraintLayout>
Using fix width or height
Need to use same Guideline for both top and bottom constraint like:
app:layout_constraintTop_toTopOf="#id/guideline_30"
app:layout_constraintBottom_toBottomOf="#id/guideline_30"
xml:
<android.support.constraint.ConstraintLayout
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">
<ImageView
android:id="#+id/imgLogo"
android:layout_width="150dp"
android:layout_height="150dp"
app:layout_constraintTop_toTopOf="#id/guideline_30"
app:layout_constraintBottom_toBottomOf="#id/guideline_30"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:src="#drawable/splash_logo" />
<android.support.constraint.Guideline
android:id="#+id/guideline_30"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.30" />
</android.support.constraint.ConstraintLayout>
output:
Using width and height based on the ratio
As you are using both width and height based on ratio so that it's not centered.
But to get your desired result you can also set Guideline = 0.15 (0.3 / 2) and modify constraintTop and constraintBotttom
xml:
<android.support.constraint.ConstraintLayout
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">
<ImageView
android:id="#+id/imgLogo"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="H,1:1"
app:layout_constraintEnd_toStartOf="#+id/guidelineV_75"
app:layout_constraintStart_toEndOf="#+id/guidelineV_25"
app:layout_constraintTop_toTopOf="#+id/guideline_15"
app:srcCompat="#drawable/ic_launcher_background" />
<android.support.constraint.Guideline
android:id="#+id/guideline_15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.15" />
<android.support.constraint.Guideline
android:id="#+id/guidelineV_25"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.25" />
<android.support.constraint.Guideline
android:id="#+id/guidelineV_75"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.75" />
</android.support.constraint.ConstraintLayout>
output:
You need to constraint both the top and the bottom of the View to the guideline, like so:
<android.support.constraint.Guideline
android:id="#+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.3" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="#id/guideline"
app:layout_constraintBottom_toBottomOf="#id/guideline" />
In ConstraintLayout, for centering the View over Vertical axis of any other View Component (e.g. Guidelines, TextViews, ImageViews, layouts, etc.), you can simply follow these two steps, in XML:-
1) app:layout_constraintTop_toTopOf="#id/componentId"
2) app:layout_constraintBottom_toBottomOf="#id/componentId"
This will Equally distribute the component's View in the Vertical center.
BONUS:-
For centering the View in the Horizontal axis, use
1) app:layout_constraintLeft_toLeftOf="#id/componentId"
or
app:layout_constraintStart_toStartOf="#id/componentId"
2) app:layout_constraintRight_toRightOf="#id/componentId"
or
app:layout_constraintEnd_toEndeOf="#id/componentId"
I want to display the list view in half of the screen and the other half contains some static content. When i tried to put the listview, the whole screen is repeated in the loop. I want only that particular part the screen in listview. Can anyone help?
This is my MainActivity.java
List<HashMap<String,String>> aList = new ArrayList<HashMap<String,String>>();
for(int i=0;i<6;i++){
HashMap<String, String> hm = new HashMap<String,String>();
hm.put("text", menu[i]);
hm.put("icon", Integer.toString(image[i]) );
aList.add(hm);
}
String[] from = { "icon","text" };
int[] to = { R.id.icon,R.id.text};
SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), aList, R.layout.activity_test_main, from, to);
ListView listView = ( ListView ) findViewById(R.id.list);
listView.setAdapter(adapter);
This my activity_test_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/new_background"
>
<ImageView
android:layout_width="100dip"
android:layout_height="100dip"
android:layout_marginTop="30dip"
android:layout_gravity="center_horizontal"
android:src="#drawable/katrina" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Katrina"
android:textColor="#FFFFFF"
android:textStyle="italic"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dip"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="katrina#gmail.com"
android:textColor="#FFFFFF"
android:textStyle="italic"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dip"/>
<RelativeLayout
android:id="#+id/single_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dip">
<ImageView
android:id="#+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dip"
android:textColor="#FFFFFF"/>
<ImageView
android:id="#+id/arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"/>
</RelativeLayout>
If I'm getting this right you want to display the ListView below the arrow ImageView?
You can simply put the ListView below the ImageView inside the RelativeLayout, then set the android:layout_below param to the id of the ImageView...arrow and finally make sure your ListView's id is set to list
I'm trying to mimic an action in the Twitter android app. When you long press/swipe a tweet (list item) it looks like this
This makes it easy for the user to take actions on the list item without leaving the screen. How can I do something similar in my app?
For now I've added a context menu which looks like this (notice that it fades out rest of the app).
I achieved this by registerForContextMenu(listView)
Currently, my list is like this:
ListAdapter adapter = new SimpleAdapter(
MainActivity.this, myList,
R.layout.list_items, new String[] {LI_ID,
LI_NAME, LI_COUNT}, new int[] {
R.id.li_id, R.id.li_name, R.id.li_count});
setListAdapter(adapter);
and my layout is simply like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/li_id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone" />
<TextView
android:id="#+id/li_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="16dip"
android:textColor="#000000"
android:paddingTop="15dip"
android:paddingBottom="15dip"
android:paddingLeft="10dip"
android:textStyle="bold"/>
<TextView android:id="#+id/li_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:textColor="#ffffff"
android:textStyle="bold"
android:background="#9ed321"
android:paddingRight="3dip"
android:paddingLeft="3dip"/>
</RelativeLayout>
Have you looked tried an expandable list view ?
http://developer.android.com/reference/android/widget/ExpandableListView.html
http://www.youtube.com/watch?v=mwE61B56pVQ
You could just nest another layout in each individual ListView item that's initially invisible, then just toggle the visibility of the view on a long click event.
For example:
<?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"
android:animateLayoutChanges="true" >
<TextView
android:id="#+id/main_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:padding="16dp"
android:layout_gravity="center" />
<LinearLayout
android:id="#+id/hidden_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Delete" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Edit" />
</LinearLayout>
</LinearLayout>
Then in your activity, just set an onItemLongClickListener on your ListView, and toggle the
visibility of the hidden_view:
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id){
LinearLayout mView = view.findViewById(R.id.hidden_view);
switch(mView.getVisibility()){
case View.VISIBLE:
mView.setVisibility(View.GONE);
break;
case View.GONE:
mView.setVisibility(View.VISIBLE);
break;
}
}
}