<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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=".ProfileMainActivity">
<ImageView
android:layout_width="match_parent"
android:layout_height="240dp"
android:src="#drawable/cp"
android:scaleType="centerCrop"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="240dp"
android:clipToPadding="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_marginBottom="8dp"
android:layout_marginRight="10dp"
/>
<ImageButton
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_gravity="top|left"
android:layout_marginTop="200dp"
android:layout_marginLeft="20dp"
android:src="#drawable/dp"
android:scaleType="centerCrop"
android:background="?attr/selectableItemBackgroundBorderless"
/>
</FrameLayout>
I need the image to be cropped within the black circle , but it doesn't happen.
Moreover I noticed that the ripple from the ImageButton touch goes out in a circular area, so I was guessing that there might be some way to fit the image within that area itself.
Dimension of Stock Image:- 495x495
I suggest you recreate the image as circular bitmap. You can use this a method like this one. Just introduce the necessary round pixels.
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) {
if (bitmap == null)
return null;
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap
.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
final RectF rectF = new RectF(rect);
final float roundPx = pixels;
paint.setAntiAlias(true);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
Using a library you can easily fixed this issue> This may helps you com.mikhaellopez:circularimageview:3.0.2. Hope that it works and solve your issue
Related
Hey fellow programmers,
I was just programming in a listView and implementing actions for tapping a list element until I got to a point where I wanted to keep things recursively.
Taken this ClickListener, I would like to have the image next to the list element changed when tapped.
list.add(Model("firstelement","description 1", R.drawable.button_activated))
list.add(Model("secondelement","description 2",R.drawable.button_activated))
listview.adapter = MyAdapter(this, R.layout.row, list)
var elementArray: IntArray = intArrayOf(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
listview.setOnItemClickListener{ parent: AdapterView<*>, view: View, position:Int, id: Long ->
val currentimage = ? //here I'd like to retrieve the imageview of the tapped list item
val img: ImageView = findViewById(R.id.currentimage)
if (elementArray.get(position)==0){
img.setImageResource(R.drawable.button_activated)
elementArray.set(position,1)
}
else if (elementArray.get(position)==1){
img.setImageResource(R.drawable.button_dectivated)
elementArray.set(position,0)
The images are added to the list together with the text view.
How can I retrieve them to change them? Tried listview.getItemIdAtPosition but that leads to errors.
I bet there is a way - I just don't see it. Thanks in advance for any hint!
In addition, here is my layout row.xml where the list gets loaded into:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
>
<ImageView
android:layout_width="75dp"
android:layout_height="75dp"
android:id="#+id/image0"
android:src="#mipmap/ic_launcher"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView1"
android:text="first element"
android:textStyle="bold"
android:textSize="20sp"
android:layout_margin="5dp"
android:textColor="#000"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView2"
android:text="second element"
android:textSize="18sp"
android:layout_margin="5dp"
android:textColor="#a9a9a9"
/>
</LinearLayout>
</LinearLayout>
Just resolved it on my own with the help of this solution: Android: Dynamically change Image in Listview
Had to access the lower imageView of the current view: ImageView = view.findViewById(R.id.image)
I have 5 checkboxes and each checkbox's' text is misaligned vertically from the center of the checkbox. I have tried adding a padding or a marging to the chckbox which has not helped, cause to my knowledge you can't add a padding specifically to the text. Heres an image that might explain my problem a little better!
Checkbox text is misaligned on the first checkbox. The result I want is the 4th checkbox.
EDIT
I create the checkboxes programmatically from an array:
LinearLayout typeLinLayout = (LinearLayout)findViewById(R.id.typeLinLay);
TableRow.LayoutParams checkParams = new TableRow.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
checkParams.setMargins(0, 15, 0, 0);
for (int k = 0; k < config.checkBoxTypeFindViewById.length; k++)
{
CheckBox checkBox = new CheckBox(this);
checkBox.setLayoutParams(checkParams);
typeLinLayout.addView(checkBox, checkParams);
checkBox.setId(config.checkBoxTypeFindViewById[k]);
checkBox.setText(config.checkBoxTextType[k]);
checkBox.setOnClickListener(onCheckboxClickedType);
checkBox.setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
checkBox.setGravity(Gravity.LEFT);
checkBox.setTextDirection(View.TEXT_DIRECTION_ANY_RTL);
checkBox.setTextSize(16);
checkBox.setAllCaps(true);
}
Heres the xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#color/mainTextBGColor">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginStart="15dp"
android:layout_marginEnd="15dp">
<TextView
android:id="#+id/typesText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="30dp"
android:layout_marginBottom="10dp"
android:textSize="#dimen/optionsHeaders"
android:fontFamily="#font/lato"
android:textColor="#color/mainBGColor"
android:text="#string/optionsType"/>
<LinearLayout
android:id="#+id/typeLinLay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:backgroundTint="#color/mainBGColor">
</LinearLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
Any help is much appreciated!
Is there anyway to show HereMaps inside a Linear Layout?
This is my layout file and I want to show map in firstMap (LinearLayout).
<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="com.apploft.tabs.MyTabFragment">
<RelativeLayout
android:id="#+id/confirmed"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/firstMap"
android:layout_width="match_parent"
android:layout_height="130dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
android:background="#color/cardview_shadow_start_color"
android:orientation="horizontal">
<!-- Map Fragment embedded with the map object -->
</LinearLayout>
</FrameLayout>
By adding maoview inside LinearLayout and then calling
<com.here.android.mpa.mapping.MapView
android:id="#+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="visible"/>
in the fragment
MapView mapColView = (MapView) colTabView.findViewById(R.id.mapview);
map = new com.here.android.mpa.mapping.Map();
map.setCenter(new GeoCoordinate(51.509865, -0.118092, 0.0), com.here.android.mpa.mapping.Map.Animation.NONE);
// Set the zoom level to the average between min and max
map.setZoomLevel((map.getMaxZoomLevel() + map.getMinZoomLevel()) / 2);
mapColView.setMap(map);
Also test/check onResume() onPause().
Use a MapView instead of a MapFragment in this case. The documentation is linked here for starter and here for premium.
First of all, excuse me if it sounds duplicate. I have visited so many threads but couldn't find a suitable answer of my problem. I have tried ScrollingMovementMethod, android:scrollbar, wrap_content in the parent and many other things suggested in those threads but nothing worked for me. Feel free to edit the title as I couldn't find a better one.
Problem Description
I have a list view and each row of the listview has three controls 1. Image View (to Show the contact image) 2. TextView (to show the Contact name) 3. TextView (to show the status message of the contact (if available)).
What I have tried:-
1. XML layout ,
<?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" >
<ImageView
android:id="#+id/icon"
android:layout_width="22dp"
android:layout_height="50dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="15dp"
android:contentDescription="#string/strBuddyImage" >
</ImageView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minHeight="56dp" >
<TextView
android:id="#+id/uNameTxt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/customMsg"
android:minHeight="?android:attr/listPreferredItemHeight"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="#dimen/fontSizeListRowHeader" />
<TextView
android:id="#+id/customMsg"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:maxLines="4"
android:textSize="#dimen/fontSizeListRowText"
android:textStyle="italic" />
</RelativeLayout>
</LinearLayout>
Adapter Which extends ArrayAdapter (which only overrides the getView method)
static class ViewHolder {
public ImageView imageView;
public TextView uNameTxtView;
public TextView custMsgTxtView;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View rowView = convertView;
// Log.d("BuddyListAdapter", "Inside getView() " + position);
if ( rowView == null ) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rowView = inflater.inflate(R.layout.buddy_listview_row_layout, parent, false);
viewHolder = new ViewHolder();
viewHolder.uNameTxtView = (TextView) rowView.findViewById(R.id.uNameTxt);
viewHolder.imageView = (ImageView) rowView.findViewById(R.id.icon);
viewHolder.custMsgTxtView = (TextView) rowView.findViewById(R.id.customMsg);
rowView.setTag(viewHolder);
}
viewHolder = (ViewHolder) rowView.getTag();
synchronized (buddyList) {
buddy = buddyList.get(position);
}
viewHolder.uNameTxtView.setText(buddy.getDisplayName());
viewHolder.custMsgTxtView.setText(buddy.getCustomMessage());
// Change the icon for users who are offline
if ( buddy.getState() == 0 ) {
viewHolder.imageView.setImageResource(R.drawable.offline);
} else {
viewHolder.imageView.setImageResource(R.drawable.online);
}
// rowView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
return rowView;
}
What I get
Desired
I want to show all the rows of list view of same size and if someone has a bigger Status message (Which needs multiple lines) I would like to show the name of the person and first few lines (say 4) of the status message. No matter how big the status message is name should be always visible to the user.. How can I do that ?
Please point if any other mistake you find in the code.
One thing i noticed is you use a lot of hardcoded dimensions,is that really necesary? using wrap_content would be better practice on most layouts,that way you let android handle it.
As far as your question is concerned you can do two things:
1)Your two EditTexts are inside a relative layout,and if customMsg is 4 lines long,it will get scrolled ,and you'll loose your uNameTxt so you should limit customMsg more,to something like two lines,or less. OR if you are ok with loosing some parts of the code you could adapt your layout this way
<TextView
android:id="#+id/uNameTxt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
layout_alignParentTop="true"
android:minHeight="?android:attr/listPreferredItemHeight"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="#dimen/fontSizeListRowHeader" />
<TextView
android:id="#+id/customMsg"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/uNameTxt"
android:maxLines="4"
android:textSize="#dimen/fontSizeListRowText"
android:textStyle="italic" />
it should scroll down no more and you should see Name and a part of customMsg
2)Edit your layout to something more efficient like:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minHeight="56dp">
<ImageView
android:id="#+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_marginRight="15dp"
android:contentDescription="sasd" >
</ImageView>
<TextView
android:id="#+id/uNameTxt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:singleLine="true"
android:layout_toRightOf="#+id/icon"
android:textSize="#dimen/fontSizeListRowHeader"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<TextView
android:id="#+id/customMsg"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/uNameTxt"
android:maxLines="2"
android:layout_toRightOf="#+id/icon"
android:textSize="#dimen/fontSizeListRowText"
android:textStyle="italic" />
</RelativeLayout>
I agree with sokie on the use of wrap_content. I tend to use LinearLayout a lot since it provides a consistent layout on various display sizes. One way of implementation is as follows. By replacing your inner RelativeLayout to LinearLayout, your text view containing the name will always be displayed and the message text view will display the maximum possibles lines (or can be limited by specifying the maxLines) with the available remaining/space. If you would like to display the whole status message, then you can achieve this by changing the parent LinearLayout height parameter to wrap_content.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="56dp"
android:minHeight="?android:attr/listPreferredItemHeight">
<ImageView
android:id="#+id/icon"
android:layout_width="22dp"
android:layout_height="50dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="15dp" >
</ImageView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/uNameTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<TextView
android:id="#+id/customMsg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="4"
android:textStyle="italic"
/>
</LinearLayout>
</LinearLayout>
I am trying to get an image to move to certain x and y withing this application.I have tried with layoutParams via searching but it is not working here is my full application code.
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="fill_parent"
android:layout_height="fill_parent"
android:screenOrientation="portrait">
<ImageView android:id="#+id/ImageView01" android:layout_height="wrap_content" android:layout_width="fill_parent" android:scaleType="fitXY" android:src="#drawable/myImage1" android:layout_marginTop="5dp"></ImageView>
<FrameLayout android:id="#+id/FrameLayout01" android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="#+id/marker" android:src="#drawable/marker"></ImageView>
</FrameLayout>
</LinearLayout>
myapp Java
ImageView marker;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
marker=(ImageView)findViewById(R.id.marker);
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
lp.setMargins(35, 90, 0, 0);
marker.setLayoutParams(lp);
marker.invalidate();
}
}
My end goal is to move the marker image over myImage1 at different Locations
You can get the size of the phone with this code:
DisplayMetrics metrics = new DisplayMetrics();
((Activity)c).getWindowManager().getDefaultDisplay().getMetrics(metrics);
screenWidth = ((int)metrics.xdpi);
screenHeight = ((int)metrics.ydpi);
You can use setPadding and the width and height of the phone can be got by the code above. I had positioning problems too and this was the solution.