android-relativelayout

Dynamically adding a button to RelativeLayout not working correctly

爱⌒轻易说出口 提交于 2019-12-24 14:24:02
问题 My goal is to add a number of buttons (in a 4 column grid) to a RelativeLayout depending on how many "items" are in the database. When I was first learning how to add buttons to a RelativeLayout I just created 6 static buttons and added them the following way (ItemButton is simple class that extends Button): private void loadItemButtons2(){ itemButtonLayout = (RelativeLayout)findViewById(R.id.itemButtonLayout); itemButtonLayout.removeAllViews(); ArrayList<Item> items = db.getAllActiveItems();

RelativeLayout is not matching parent width inside a ToolBar

感情迁移 提交于 2019-12-24 03:15:08
问题 So I have a customized toolbar on my home screen, and within this toolbar is a RelativeLayout . I have the layout width set to match_parent and the parent of the relative layout is just the width of the screen. For some reason, it does not fit the width of the screen because the left edge is some distance away from the edge of the screen. I am not sure why this is but it is making positioning within the RelativeLayout a bit more difficult. This is my .xml <android.support.v7.widget.Toolbar

Fold up a Layout but keep another at the bottom

眉间皱痕 提交于 2019-12-23 23:08:18
问题 I've got this layout: Without colors: https://i.stack.imgur.com/OdSda.png Layout for the tabs (separate xml file) RelativeLayout 1 surrounding everything else A, B, C all have their own LinearLayout in RelativeLayout 2 The horizontal line, D (in a LinearLayout) and the "OK" button have their own RelativeLayout 3 And there's RelativeLayout 4 (=footer) for E What I want to happen if I click on the EditText next to D and the keyboard opens up: 4 stays at the bottom and is hidden behind the

android gridlayout not showing in emulator API 22

旧城冷巷雨未停 提交于 2019-12-23 22:37:45
问题 I have an app that functions exactly as desired on an actual device Nexus 6P running API 23 and an emulated 6P, 5 & 4 running API 24, but is showing odd behaviour wrt GridLayout on emulated Nexus 5 & 4 running API 22. The app only has a single activity with multiple RelativeLayout s that are programmatically set .VISIBLE & .INVISIBLE . In one such RelativeLayout I have 2 GridLayout s as follows. When emulating API 22, the bottom GridLayout does not show but the top one always does

Is it possible to set gravity programmatically for RecyclerView children in Android?

≡放荡痞女 提交于 2019-12-23 15:18:43
问题 I'm trying to set gravity for children in RecyclerView, but it looks like the LayoutParams does not have a gravity method. I have tried the following: RecyclerView.LayoutParams params = new RecyclerView.LayoutParams( RecyclerView.LayoutParams.WRAP_CONTENT, RecyclerView.LayoutParams.WRAP_CONTENT); I have also tried the following: RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); In both

How to place transparent buttons over an image relatively?

痴心易碎 提交于 2019-12-23 02:54:24
问题 I am looking for a way in Android how to place some transparent buttons over a (background) image so I have good control to position the buttons and they stay were they meant to be also if the screen is much larger. As you can imagine the image contains also the button art... The best thing would be if I could position the buttons by using percentage, but sadly this is not possible in Android. This is my current base of the code: <RelativeLayout xmlns:android="http://schemas.android.com/apk

How to give layout weight in RelativeLayout?

孤街浪徒 提交于 2019-12-23 02:42:35
问题 I have created a dialpad using LinearLayout . Here is the code <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:gravity="center" android:orientation="vertical"

Responsive layout on Android

孤街浪徒 提交于 2019-12-23 02:42:11
问题 I have three elements in layout, two TextViews and one ImageView between them. I'm trying to achieve this behavior: image (arrow) has 9patch image is wide as possible image has set minimal width right and left texts go wider with longer text but only to meet image's minWidth, then new line appears Below are few screenshots from Android Studio layout preview, gained with different layouts. What I have tried: Relative layout: image centered, minWidth set, texts have set toRightOf/toLeftOf

Aligning images about right bottom corner

♀尐吖头ヾ 提交于 2019-12-22 09:59:32
问题 I am using relative layout to superimpose one smaller image on top of a larger one. I want the bottom-right corner of the smaller image to coincide with B-R corner of the larger image. I'm using margin parameters in my layout XML (specifying measurement in dips) but this doesn't seem to work for all devices and resolutions - in some cases the small image is shifted by 4-5px from the border. Is it possible to specify the position of the smaller image without pixel values? I.e. with gravity or

how to half overlap imageview on another imageview in android

夙愿已清 提交于 2019-12-22 05:13:46
问题 how can I overlap images half on one another from layout XML file like this image. 回答1: Simply you can use RealtiveLayout and negative margins <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/activity_landing" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/screen_background"> <ImageView android:background="@color/black" android:id="@+id/img_background" android