android-layout

MeasureSpec returns a 0 value - onMeasure()

本小妞迷上赌 提交于 2020-02-02 06:16:24
问题 I have searched for answers regarding this but haven't found a solution. So i am requesting help here. I am creating a custom View. I have overridden onMeasure. Code given Below. @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){ super.onMeasure(widthMeasureSpec, heightMeasureSpec); int widthSize,heightSize; int measureWidthSpec = MeasureSpec.getMode(widthMeasureSpec); int measureHeightSpec = MeasureSpec.getMode(heightMeasureSpec); widthSize = getCircleWidth

In Android, how do I position an image on top of another to look like a badge?

给你一囗甜甜゛ 提交于 2020-02-02 02:19:26
问题 Please see below: I tried using Absolute layout, but that's deprecated. I appreciate your help, thanks. 回答1: RelativeLayout is a great option. <?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" > <ImageView android:id="@+id/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="5dp" android:scaleType="centerCrop"

TabLayout gravity center is not working

ぃ、小莉子 提交于 2020-02-01 23:58:28
问题 I have a TabLayout, where I want the tabs to be displayed in the center of the screen. Below is the XML for my TabLayout. <android.support.design.widget.TabLayout android:id="@+id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:background="@color/white" app:tabGravity="center" app:tabIndicatorColor="@color/about_tab_selected" app:tabIndicatorHeight="4dp" app:tabMode="scrollable" app:tabPaddingEnd="20dp" app:tabPaddingStart

RecyclerView is not trully wrap_content at the ScrollView

可紊 提交于 2020-02-01 05:29:24
问题 I have a ScrollView, which contains a vertical LinearLayout. This is a place, where I add some amount of Views called "Section". "Section" is a LinearLayout, which contains a TextView and `RecyclerView. <ScrollView android:id="@+id/main_scrollview" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:id="@+id/sections_layout" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" /> </ScrollView>

Adding constraints programmatically

℡╲_俬逩灬. 提交于 2020-02-01 02:44:26
问题 What is the translation to java code of the following XML instructions used in a layout definition with a constraint layout? app:layout_constraintBottom_toBottomOf="@+id/Button1" app:layout_constraintTop_toTopOf="@+id/Button1" app:layout_constraintLeft_toLeftOf="@+id/Button2" app:layout_constraintRight_toRightOf="Button2" 回答1: Here is an example of adding constraints programatically, ConstraintLayout mConstraintLayout = (ConstraintLayout)fndViewById(R.id.mainConstraint); ConstraintSet set =

How do I trigger the redraw of a parent View when any of it's children are redrawn?

被刻印的时光 ゝ 提交于 2020-01-31 08:28:46
问题 Background I have written a custom Android View based on a LinearLayout which I have called ReflectingLayout . The idea is fairly simple, to render a reflection effect below any child Views declared within the ReflectingLayout . e.g... I am achieving this by overriding dispatchDraw() in ReflectingLayout as follows: @Override protected void dispatchDraw(Canvas canvas) { Bitmap bitmap = Bitmap.createBitmap(...); Canvas tempCanvas = new Canvas(bitmap); // Draw child views to bitmap using

onFinishInflate() never gets called

给你一囗甜甜゛ 提交于 2020-01-31 06:17:10
问题 Who/What calls onFinishInflate()? No matter how I inflate my layout files (in code) this method never seems to get triggered. Can anyone give me an example or tell me when onFinishInflate() actually get called? 回答1: View.onFinishInflate() is called after a view (and its children) is inflated from XML. Specifically, it is during a call to LayoutInflater.inflate(...) that onFinishInflate() will be called. Inflation is performed recursively, starting from the root. A view containing children may

onFinishInflate() never gets called

旧城冷巷雨未停 提交于 2020-01-31 06:16:37
问题 Who/What calls onFinishInflate()? No matter how I inflate my layout files (in code) this method never seems to get triggered. Can anyone give me an example or tell me when onFinishInflate() actually get called? 回答1: View.onFinishInflate() is called after a view (and its children) is inflated from XML. Specifically, it is during a call to LayoutInflater.inflate(...) that onFinishInflate() will be called. Inflation is performed recursively, starting from the root. A view containing children may

onFinishInflate() never gets called

点点圈 提交于 2020-01-31 06:16:08
问题 Who/What calls onFinishInflate()? No matter how I inflate my layout files (in code) this method never seems to get triggered. Can anyone give me an example or tell me when onFinishInflate() actually get called? 回答1: View.onFinishInflate() is called after a view (and its children) is inflated from XML. Specifically, it is during a call to LayoutInflater.inflate(...) that onFinishInflate() will be called. Inflation is performed recursively, starting from the root. A view containing children may

How to show icons in ActionBar overflow menu?

冷暖自知 提交于 2020-01-31 04:10:30
问题 I want to display icon in addition to menu item title in overflow dropdown menu. Is is possible? 回答1: put your menu with property android:showAsAction="always" and in xml file of menu add sub menus under that your menu like this <item android:id="@+id/mainMenu" android:icon="@drawable/launcher" android:showAsAction="always"> <menu> <item android:id="@+id/menu_logout" android:icon="@drawable/log_out" android:title="logout"/> </menu> </item> this will show the icons in menus 回答2: There is