Increasing the size of a floating sub-action-button - android

Am using a CircularFloatingActionMenu library, I have successfully implemented this library, but I want to increase the size of the 4 sub-action button
Please find below the code am using
final ImageView fabIconNew = new ImageView(this);
fabIconNew.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_new));
final FloatingActionButton rightLowerButton = new FloatingActionButton.Builder(this)
.setContentView(fabIconNew)
.build();
SubActionButton.Builder rLSubBuilder = new SubActionButton.Builder(this);
ImageView rlIcon1 = new ImageView(this);
ImageView rlIcon2 = new ImageView(this);
ImageView rlIcon3 = new ImageView(this);
ImageView rlIcon4 = new ImageView(this);
//ImageView rlIcon6 = new ImageView(this);
rlIcon1.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_contact));
rlIcon2.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_currency_info));
rlIcon3.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_exhibition));
rlIcon4.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_faq));

You can set LayoutParams in the SubactionButton.Builder
SubActionButton.Builder rLSubBuilder = new SubActionButton.Builder(this);
LayoutParams params=new LayoutParams(200,200);
rLSubBuilder.setLayoutParams(params);

LayoutParams params=new LayoutParams(80,80);
button1.setLayoutParams(params)
for more reference [circular floating action menu][2]

Related

Set height and width of a cardView in android

Im trying to set a width and height for my cardView, so once I download an image from the database, a cardView is added by it stretches the image and can't control the height, im trying to do it programatically. This is what i've got.
public void CreateCardView(final Users u) throws IOException
{
CardView.LayoutParams params = new CardView.LayoutParams(
CardView.LayoutParams.WRAP_CONTENT,
CardView.LayoutParams.WRAP_CONTENT
);
params.setMargins(10,10,10,20);
params.width = 500;
mLoginFormView = findViewById(R.id.containerGrid);
CardView card = new CardView(this);
card.setLayoutParams(params);
card.setRadius(9);
card.setCardElevation(9);
LinearLayout.LayoutParams par = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT
);
LinearLayout lin = new LinearLayout(this);
lin.setOrientation(LinearLayout.VERTICAL);
lin.setLayoutParams(par);
final ImageButton Name = new ImageButton(this);
Name.setAdjustViewBounds(true);
Name.setScaleType( ImageView.ScaleType.CENTER);
mLoginFormView.bringToFront();
// Name.setBackground(bdrawable);
Name.setAdjustViewBounds(true);
//Name.setImageBitmap(i.getImage().get(0));
lin.bringToFront();
mLoginFormView.addView(card);
card.setElevation(15);
System.out.println("Hello?");
//Name.setImageBitmap( scaled);
TextView username = new TextView(this);
TextView sport = new TextView(this);
username.setText(u.getUsername());
sport.setText(u.getEmail());
lin.addView(Name);
lin.addView(username);
lin.addView(sport);
card.addView(lin);
card.setElevation(15);
Instead of this code:
CardView.LayoutParams params = new CardView.LayoutParams(
CardView.LayoutParams.WRAP_CONTENT,
CardView.LayoutParams.WRAP_CONTENT
);
params.setMargins(10,10,10,20);
params.width = 500;
Try this code:
card.setLayoutParams(new LayoutParams(width, height));

Dynamically create Imageviews

I have to create Dynamically list of Imageview in a row, There is an other Imageview (dot Drawable) under Each Imageview.
see below pic which is my desired view.
Here is my source.
for (int i = 0; i < 9; i++) {
RelativeLayout.LayoutParams params1 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
RelativeLayout.LayoutParams params2 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
ImageView catImg = new ImageView(getApplicationContext());
catImg.setImageResource(bottDrawableArr[i]);
catImg.setId(View.generateViewId());
int dp = (int) utiles.convertDpToPixel(27, getApplicationContext());
params1.height = dp;
params1.width = dp;
ImageView dotImg = new ImageView(getApplicationContext());
dotImg.setImageResource(R.mipmap.dot);
dotImg.setId(View.generateViewId());
params2.addRule(RelativeLayout.BELOW, dotImg.getId());
dockBg.addView(catImg, params1);
dockBg.addView(dotImg, params2);
}
But I am Unable to get my desire view,
while my views show like this
I tried to put dot under each image but unable to achieve that.
The best way is working with some LinearLayout, something like this:
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.HORIZONTAL);
for (int i = 0; i < 9; i++) {
LinearLayout layoutChild = new LinearLayout(this);
layoutChild.setOrientation(LinearLayout.VERTICAL);
RelativeLayout.LayoutParams params1 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
RelativeLayout.LayoutParams params2 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
ImageView catImg = new ImageView(getApplicationContext());
catImg.setImageResource(bottDrawableArr[i]);
catImg.setId(View.generateViewId());
int dp = (int) utiles.convertDpToPixel(27, getApplicationContext());
params1.height = dp;
params1.width = dp;
ImageView dotImg = new ImageView(getApplicationContext());
dotImg.setImageResource(R.mipmap.dot);
dotImg.setId(View.generateViewId());
params2.addRule(RelativeLayout.BELOW, dotImg.getId());
layoutChild.addView(catImg, params1);
layoutChild.addView(dotImg, params2);
layout.addView(layoutChild);
}
dockBg.addView(layout);
Note: it's better to delete the unnecessary properties like setting some rules...
params2.addRule(RelativeLayout.BELOW, dotImg.getId());
This line of code looks like you are trying to add a rule to put the dotImg below the dotImg. Replacing that with catImg.getId() should fix your issue.
It might be a good idea to consider a RecyclerView though, Or if it is a static array (always the same items) then you could make a new layout file and just inflate it when you need it.

Create a custom number picker

So because of the limited support library for the number picker (And because it's WAAY too big), I'm making my own number picker. Unfourtunately, it's not appearing correctly.
Any help on fixing it would be great.
Up arrow and down arrows occupy the same space (overlapping each other so that only the down arrow appears). The down arrow should be UNDER the text representing the number.
Any idea why this is?
Here's the screenshot:
And here's the code for it:
//"Number-Picker"
LinearLayout numPicker = new LinearLayout(context);
numPicker.setOrientation(LinearLayout.VERTICAL);
numPicker.setLayoutParams(pickerItemParams);
LinearLayout.LayoutParams upDownParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1.0f);
//Up button
LinearLayout upSpace = new LinearLayout(context);
ImageView upArrow = new ImageView(context);
upArrow.setBackgroundResource(R.drawable.arrow_up);
upSpace.setLayoutParams(upDownParams);
upSpace.addView(upArrow);
//text
LinearLayout numSpace = new LinearLayout(context);
TextView pickerNum = new TextView(context);
pickerNum.setText(String.valueOf(textValue));
numSpace.setLayoutParams(upDownParams);
numSpace.addView(pickerNum);
//down
LinearLayout downSpace = new LinearLayout(context);
ImageView downArrow = new ImageView(context);
upArrow.setBackgroundResource(R.drawable.arrow_down);
downSpace.setLayoutParams(upDownParams);
downSpace.addView(downArrow);
numPicker.addView(upSpace);
numPicker.addView(numSpace);
numPicker.addView(downSpace);
//down
LinearLayout downSpace = new LinearLayout(context);
ImageView downArrow = new ImageView(context);
upArrow.setBackgroundResource(R.drawable.arrow_down); // <----- Should be downArrow
downSpace.setLayoutParams(upDownParams);
downSpace.addView(downArrow);
This might cause your downArrow to actually exist but its ImageView is missing its image.

How display some ImageView in a RelativeLayout?

I have a RelativeLayout
RelativeLayout myLayout = new RelativeLayout(this);
Then, I add 2 ImageView in this Layout:
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(20, 20);
ImageView img1 = new ImageView(this);
// Here I give the position of img1
ImageView img2 = new ImageView(this);
// And here the position and img2
myLayout.addView(img1, params);
myLayout.addView(img2, params);
setContentView(myLayout);
And here I have a problem: I want to show and click on the 2 ImageViews, but only the img2 is visible on my screen.
Is there a problem with the z-index or something else?
Since you are using RelativeLayout and same params for both ImageView one will be overlapped with the other. So define params for both. Add rule to each param for positioning it. And then give addView().
For eg:
RelativeLayout myLayout = new RelativeLayout(this);
ImageView img1 = new ImageView(this);
RelativeLayout.LayoutParams firstImageParams = new RelativeLayout.LayoutParams(
android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
leftArrowParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
ImageView img2 = new ImageView(this);
RelativeLayout.LayoutParams secImageParams = new RelativeLayout.LayoutParams(
android.view.ViewGroup.LayoutParams.WRAP_CONTENT,android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
rightArrowParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
myLayout.addView(img1, firstImageParams);
myLayout.addView(img2, secImageParams);
setContentView(myLayout);

In Android How To Add Internal Image With Java?

I have an image in "src\main\res\drawable\gate_logo.png" which looks like this :
My Java code looks like this :
LinearLayout Demo_Layout = new LinearLayout(context);
Demo_Layout.setId(View.generateViewId());
// Demo_Layout.setBackgroundColor(Color.rgb(88, 188, 218));
Demo_Layout.setBackgroundColor(Color.rgb(98, 198, 238));
Demo_Layout.setHorizontalGravity(Gravity.CENTER);
Demo_Layout.setVerticalGravity(Gravity.CENTER);
addView(Demo_Layout, LinearLayout.LayoutParams.MATCH_PARENT,328);
TextView textView = new TextView(context);
textView.setId(View.generateViewId());
textView.setGravity(Gravity.CENTER);
textView.setTextSize(20);
textView.setText(Html.fromHtml("<P><Br><big>GATE Demo</big><P>[ Graphic Access Tabular Entry ]<Br><small>An Interception-resistant Authentication System</small>"));
// Demo_Layout.addView(textView, LinearLayout.LayoutParams.MATCH_PARENT, 328);
// Demo_Layout.addView(textView, 600, 328);
// int resID = getResources().getIdentifier("gate_logo.png", "drawable", "package.name");
int resID = getResources().getIdentifier("gate_logo_s.png", "drawable", context.getPackageName());
ImageView gateLogoView = new ImageView(context);
gateLogoView.setImageResource(resID);
// gateLogoView.setScaleType(ImageView.ScaleType.CENTER_CROP);
// gateLogoView.setScaleType(ImageView.ScaleType.FIT_XY);
gateLogoView.setLayoutParams( new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
gateLogoView.setX(1);
gateLogoView.setY(1);
LinearLayout.LayoutParams vp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
gateLogoView.setLayoutParams(vp);
gateLogoView.setImageResource(resID);
// Demo_Layout.addView(gateLogoView, 600, 328);
Demo_Layout.addView(gateLogoView);
LinearLayout Button_Layout = new LinearLayout(context);
Button_Layout.setId(View.generateViewId());
Button_Layout.setBackgroundColor(Color.rgb(168, 98, 188));
Button_Layout.setHorizontalGravity(Gravity.CENTER);
Button_Layout.setVerticalGravity(Gravity.CENTER);
RelativeLayout.LayoutParams lp1 = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, 138);
lp1.addRule(RelativeLayout.BELOW, Demo_Layout.getId());
addView(Button_Layout, lp1);
Button Registration_Button=new Button(context);
Registration_Button.setText("Registration");
Registration_Button.setAllCaps(false);
Registration_Button.setOnClickListener(Registration_Demo_Listener);
Button_Layout.addView(Registration_Button);
Button Login_Button=new Button(context);
Login_Button.setText("Login");
Login_Button.setAllCaps(false);
Login_Button.setOnClickListener(Login_Demo_Listener);
Button_Layout.addView(Login_Button);
Button Auto_Demo_Button=new Button(context);
Auto_Demo_Button.setText("Auto Demo");
Auto_Demo_Button.setAllCaps(false);
Auto_Demo_Button.setOnClickListener(Auto_Demo_Listener);
Button_Layout.addView(Auto_Demo_Button);
I also have a half size smaller version of the image in the same directory : gate_logo_s.png
I've tried different combinations, but why is the logo image not showing up ?
Screenshot look like this :
Replace these lines:
int resID = getResources().getIdentifier("gate_logo_s.png", "drawable", context.getPackageName());
ImageView gateLogoView = new ImageView(context);
gateLogoView.setImageResource(resID);
with these:
ImageView gateLogoView = new ImageView(context);
gateLogoView.setImageResource(R.drawable.gate_logo);

Categories

Resources