I want to show the image from a location from my phone in ImageView. But when I use scaletype FIT_XY the image gets stretched out.
Here is the code for my layout
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:layout_above="#+id/cancel_show_war">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/show_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="24sp"
android:autoSizeTextType="uniform"/>
<TextView
android:id="#+id/show_startdate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="24sp"
android:autoSizeTextType="uniform"/>
<TextView
android:id="#+id/show_enddate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="24sp"
android:autoSizeTextType="uniform"/>
<ImageView
android:id="#+id/show_image_war"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
</ScrollView>
<Button
android:id="#+id/cancel_show_war"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/mybutton"
android:text="#string/cancel_input"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"/>
</RelativeLayout>
The code where I get the image and put it in my ImageView
File img_file = new File(imgPath);
ImageView imgView = findViewById(R.id.show_image_war);
imgView.setImageURI(Uri.fromFile(img_file));
imgView.setScaleType(ImageView.ScaleType.FIT_XY);
And finally a picture of the strechted out picture
Related
I have a nestedscrollview with content like some RelativeLayout, CardViews and textviews. I am using a floatingactionbutton library for some reasons, as well. So I can't use any behavior for it. I don't know how I should handle the scrollchangelistener from scrollview to hide and show the fab dynamically like a behavior.
Now, When programs or output cover full page of intent, the fab is totally disappeared. It may be behind the content. I cant access fab. I want the FloatingActionButton over the scrollview. Or show and hide the fab is also need. Please tell how to achieve that concept?
Any suggestions how to hide and show the fab while scrolling?
<ScrollView
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:fab="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:scrollbars="none"
android:background="#fff"
android:fillViewport="true"
xmlns:android="http://schemas.android.com/apk/res/android">
<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="match_parent"
android:layout_height="match_parent"
tools:context=".programs.PrintANumber">
<android.support.v7.widget.CardView
android:id="#+id/program_title_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="6dp"
app:cardElevation="2dp"
android:layout_below="#id/definition_content"
android:layout_centerHorizontal="true"
app:contentPadding="15dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Print a Number"
android:textColor="#color/colorPrimaryDark"
android:textAlignment="center"
android:textSize="20sp"
android:textStyle="bold"/>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/sourcecode_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="6dp"
app:cardElevation="2dp"
android:layout_below="#id/program_title_card"
android:layout_centerHorizontal="true"
app:contentPadding="6dp">
<thereisnospon.codeview.CodeView
android:id="#+id/program"
android:layout_width="match_parent"
android:layout_height="match_parent">
</thereisnospon.codeview.CodeView>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/output_title_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="6dp"
app:cardElevation="2dp"
android:layout_below="#id/sourcecode_card"
android:layout_centerHorizontal="true"
app:contentPadding="15dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Output"
android:textColor="#color/colorPrimaryDark"
android:textAlignment="center"
android:textSize="20sp"
android:textStyle="bold"/>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/output_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="6dp"
app:cardElevation="2dp"
android:layout_below="#id/output_title_card"
android:layout_centerHorizontal="true"
app:contentPadding="6dp">
<thereisnospon.codeview.CodeView
android:id="#+id/output"
android:layout_width="match_parent"
android:layout_height="match_parent">
</thereisnospon.codeview.CodeView>
</android.support.v7.widget.CardView>
<com.github.clans.fab.FloatingActionMenu
android:id="#+id/menu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom|end"
android:paddingRight="10dp"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
fab:menu_labels_ellipsize="end"
fab:menu_labels_singleLine="true"
app:menu_icon="#drawable/fab_add"
fab:menu_backgroundColor="#ccffffff"
app:menu_colorNormal="#color/lightGrey"
android:elevation="2dp">
<com.github.clans.fab.FloatingActionButton
android:id="#+id/id_opt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/opt1"
android:padding="5dp"
fab:fab_size="mini"
fab:fab_label="Option1"
app:rippleColor="#color/colorAccent"
app:fab_colorNormal="#color/colorAccent" />
<com.github.clans.fab.FloatingActionButton
android:id="#+id/id_opt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/opt2"
android:padding="5dp"
fab:fab_size="mini"
fab:fab_label="Option2"
app:rippleColor="#color/colorAccent"
app:fab_colorNormal="#color/colorAccent" />
</com.github.clans.fab.FloatingActionMenu>
</RelativeLayout>
Try like this.
private int oldScrollYPostion = 0; // inside your class
mScrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
#Override
public void onScrollChanged() {
if (mScrollView.getScrollY() > oldScrollYPostion) {
fab.hide();
} else if (mScrollView.getScrollY() < oldScrollYPostion || mScrollView.getScrollY() <= 0) {
fab.show();
}
oldScrollYPostion = mScrollView.getScrollY();
}
});
You are using Floating action inside the scroll view tag. take it out of scroll view.
Use something like this:
<RelativeLayout
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:fab="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.github.clans.fab.FloatingActionMenu
android:id="#+id/menu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom|end"
android:paddingRight="10dp"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
fab:menu_labels_ellipsize="end"
fab:menu_labels_singleLine="true"
app:menu_icon="#drawable/fab_add"
fab:menu_backgroundColor="#ccffffff"
app:menu_colorNormal="#color/lightGrey"
android:elevation="2dp">
<com.github.clans.fab.FloatingActionButton
android:id="#+id/id_opt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/opt1"
android:padding="5dp"
fab:fab_size="mini"
fab:fab_label="Option1"
app:rippleColor="#color/colorAccent"
app:fab_colorNormal="#color/colorAccent" />
<com.github.clans.fab.FloatingActionButton
android:id="#+id/id_opt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/opt2"
android:padding="5dp"
fab:fab_size="mini"
fab:fab_label="Option2"
app:rippleColor="#color/colorAccent"
app:fab_colorNormal="#color/colorAccent" />
</com.github.clans.fab.FloatingActionMenu>
<ScrollView
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:fab="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:scrollbars="none"
android:background="#fff"
android:fillViewport="true"
xmlns:android="http://schemas.android.com/apk/res/android">
<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="match_parent"
android:layout_height="match_parent"
tools:context=".programs.PrintANumber">
<android.support.v7.widget.CardView
android:id="#+id/program_title_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="6dp"
app:cardElevation="2dp"
android:layout_below="#id/definition_content"
android:layout_centerHorizontal="true"
app:contentPadding="15dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Print a Number"
android:textColor="#color/colorPrimaryDark"
android:textAlignment="center"
android:textSize="20sp"
android:textStyle="bold"/>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/sourcecode_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="6dp"
app:cardElevation="2dp"
android:layout_below="#id/program_title_card"
android:layout_centerHorizontal="true"
app:contentPadding="6dp">
<thereisnospon.codeview.CodeView
android:id="#+id/program"
android:layout_width="match_parent"
android:layout_height="match_parent">
</thereisnospon.codeview.CodeView>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/output_title_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="6dp"
app:cardElevation="2dp"
android:layout_below="#id/sourcecode_card"
android:layout_centerHorizontal="true"
app:contentPadding="15dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Output"
android:textColor="#color/colorPrimaryDark"
android:textAlignment="center"
android:textSize="20sp"
android:textStyle="bold"/>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/output_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="6dp"
app:cardElevation="2dp"
android:layout_below="#id/output_title_card"
android:layout_centerHorizontal="true"
app:contentPadding="6dp">
<thereisnospon.codeview.CodeView
android:id="#+id/output"
android:layout_width="match_parent"
android:layout_height="match_parent">
</thereisnospon.codeview.CodeView>
</android.support.v7.widget.CardView>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
I want to dynamically change textviews height to fit cells in other linearlayout.
I tried to make this in this way:
#Override
public void onBindViewHolder(#NonNull final MyViewHolder holder, final int position) {
holder.numberCage.setText(cages.get(position).getNumberCage());
holder.eggsDescription.setText(cages.get(position).getEggsDescription());
holder.eggsFrom.setText(cages.get(position).getNumberCageFrom());
if(cages.get(position).getBasicEggs().toString().equals("true"))
holder.basicEggs.setText("Tak");
else
holder.basicEggs.setText("Nie");
holder.dateEggs.setText(cages.get(position).getDateEggs());
holder.description.setText(cages.get(position).getDescription());
holder.pigeonsInside.setText(cages.get(position).getPigeonsInside());
holder.numberCageTitle.setHeight(holder.numberCage.getHeight());
holder.eggsDescriptionTitle.setHeight(holder.eggsDescription.getHeight());
holder.eggsFromTitle.setHeight(holder.eggsFrom.getHeight());
holder.basicEggsTitle.setHeight(holder.basicEggs.getHeight());
holder.dateEggsTitle.setHeight(holder.dateEggs.getHeight());
holder.descriptionTitle.setHeight(holder.description.getHeight());
holder.pigeonsInsideTitle.setHeight(holder.pigeonsInside.getHeight());
}
class MyViewHolder extends RecyclerView.ViewHolder{
TextView numberCage,pigeonsInside,description, dateEggs, basicEggs, eggsFrom, eggsDescription, numberCageTitle, pigeonsInsideTitle, descriptionTitle, dateEggsTitle, basicEggsTitle, eggsFromTitle, eggsDescriptionTitle;
LinearLayout linearLayout, linearLayoutLeft, linearLayoutRight;
public MyViewHolder(View view){
super(view);
numberCage = view.findViewById(R.id.numberCage);
pigeonsInside = view.findViewById(R.id.pigeonsInside);
description = view.findViewById(R.id.description);
dateEggs = view.findViewById(R.id.dateEggs);
basicEggs = view.findViewById(R.id.basicEggs);
eggsFrom = view.findViewById(R.id.eggsFrom);
eggsDescription = view.findViewById(R.id.eggsDescription);
numberCageTitle = view.findViewById(R.id.numberCageTitle);
pigeonsInsideTitle = view.findViewById(R.id.pigeonsInsideTitle);
descriptionTitle = view.findViewById(R.id.descriptionTitle);
dateEggsTitle = view.findViewById(R.id.dateEggsTitle);
basicEggsTitle = view.findViewById(R.id.basicEggsTitle);
eggsFromTitle = view.findViewById(R.id.eggsFromTitle);
eggsDescriptionTitle = view.findViewById(R.id.eggsDescriptionTitle);
linearLayout = view.findViewById(R.id.linearLayout);
}
}
I have good results but my problem is that I have to scroll down and scroll up my list to "load" this heights, I don't know how to tell this so I show you screenshot.
left table is not showing
After scroll down: left table after scroll
This is my content xml:
<LinearLayout 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="wrap_content"
android:baselineAligned="true"
android:weightSum="2"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".CageList"
tools:showIn="#layout/activity_cage_list"
android:divider="#android:color/black"
android:dividerPadding="1dip"
android:showDividers="end"
android:id="#+id/linearLayout"
>
<LinearLayout
android:id="#+id/linearLayoutLeft"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:orientation="vertical">
<TextView
android:id="#+id/numberCageTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Numer klatki:"
android:textAppearance="#style/TextAppearance.AppCompat.Body1" />
<TextView
android:id="#+id/pigeonsInsideTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Gołębie w klatce:"
android:textAppearance="#style/TextAppearance.AppCompat.Body1" />
<TextView
android:id="#+id/descriptionTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Opis klatki:"
android:textAppearance="#style/TextAppearance.AppCompat.Body1" />
<TextView
android:id="#+id/dateEggsTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Data złożenia jaj:"
android:textAppearance="#style/TextAppearance.AppCompat.Body1" />
<TextView
android:id="#+id/basicEggsTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Jajka macierzyste?"
android:textAppearance="#style/TextAppearance.AppCompat.Body1" />
<TextView
android:id="#+id/eggsFromTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Jajka przełożone skąd? (klatka)"
android:textAppearance="#style/TextAppearance.AppCompat.Body1" />
<TextView
android:id="#+id/eggsDescriptionTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Opis do jajek:"
android:textAppearance="#style/TextAppearance.AppCompat.Body1" />
<View
android:layout_width="200dp"
android:layout_height="1dp"
android:background="#color/colorPrimary"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayoutRight"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.75"
android:orientation="vertical">
<TextView
android:id="#+id/numberCage"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/pigeonsInside"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/dateEggs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/basicEggs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/eggsFrom"
android:layout_width="match_parent"
android:layout_height="35.65dp" />
<TextView
android:id="#+id/eggsDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/colorPrimary"/>
</LinearLayout>
</LinearLayout>
create another file named sub_layout.xml which will have below code :-
<LinearLayout
android:id="#+id/linear"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:orientation="horizontal">
<TextView
android:id="#+id/txtTitleStatic"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.45"
android:text="Jajka przełożone skąd? (klatka)"
android:textAppearance="#style/TextAppearance.AppCompat.Body1" />
<TextView
android:id="#+id/txtTitle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".55" />
</LinearLayout>
and then use below code to include in main layout (You Content XML File):-
<include
android:id="#+id/numberCageLayout"
layout="#layout/sub_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<include
android:id="#+id/pigeonsInsideLayout"
layout="#layout/sub_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<include
android:id="#+id/descriptionLayout"
layout="#layout/sub_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Now in your Java File get their definition like :-
View numberCageLayout = findViewById(R.id.numberCageLayout);
View pigeonsInsideLayout = findViewById(R.id.pigeonsInsideLayout);
View descriptionLayout = findViewById(R.id.descriptionLayout);
TextView numberCageStatic =numberCageLayout.findViewById(R.id.txtTitleStatic);
TextView numberCage =numberCageLayout.findViewById(R.id.txtTitle);
TextView pigeonsInsideStatic =pigeonsInsideLayout.findViewById(R.id.txtTitleStatic);
TextView pigeonsInside =pigeonsInsideLayout.findViewById(R.id.txtTitle);
Now like this you don't have to worry about cell height.
I have two LinearLayout like this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:background="#drawable/border"
android:orientation="horizontal"
android:padding="10dp"
android:weightSum="2"
android:onClick="viewTipsDetail">
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:src="#mipmap/img_breakfast" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.5"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Đừng bỏ bữa sáng"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="false"
android:text="Các nghiên cứu cho thấy bữa sáng là một những điê"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:background="#drawable/border"
android:orientation="horizontal"
android:padding="10dp"
android:weightSum="2"
android:onClick="viewTipsDetail">
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:src="#mipmap/img_waterglass" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.5"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Uống đủ nước"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity=""
android:singleLine="false"
android:text="Bổ sung đủ nước cho cơ thể, ngay cả các bạn làm việc trong môi trường máy lạnh hoặc ngoài trời. Việc mất nước có thể khiến bạn căng thẳng, khó tập trung vào công việc"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>
I'm going to plan implement an onClickEvent with same method for both of them. In this occasion, the event will call viewTipsDetail() method. So how can I get the image src, the text in specific LinearLayout with only one method? And is there any possible way to auto-generate a LinearLayout like this with given detail?
This is sample, I'm going to use more LinearLayout than this, so what I need in general is a possible method for getting detail in specific LinearLayout.
<LinearLayout
id="#+id/layout1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.5"
onClick="onLayoutClick"
android:orientation="vertical">
<LinearLayout
id="#+id/layout2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.5"
onClick="onLayoutClick"
android:orientation="vertical">
In code:
#Override
public void onLayoutClick(View view) {
// click click
// view.getTag()
}
Or just use list view for achieve that...
I'm trying to inflate a list of views in a LinarLayout directly in the onCreate() method from the activity. However, I'm having a problem somewhere in the code but I really can't see it, I'm turning around this problem for two days, I'm going crazy !
The problem is that when I run the activity, the linear layout is completely empty, there is only the title.
Here is the important part of the code, KeyItems activity :
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.keyitems_layout);
initializer();
ll = (LinearLayout) findViewById(R.id.ll);
LayoutInflater inflater = LayoutInflater.from(this);
for (int i = 0; i < list.size(); i++) {
View view = inflater.inflate(R.layout.keyitem_temp, ll, false);
final TextView ind = (TextView) view.findViewById(R.id.ind);
final TextView item = (TextView) view.findViewById(R.id.item);
ind.setText(list.get(i).get("id"));
item.setText(list.get(i).get("item"));
ll.addView(view);
}
}
Here is the keyitems_layout :
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/black" >
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/black">
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp" />
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="#string/key_items"
android:textSize="36sp"
android:textColor="#color/white" />
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="4dp" />
<LinearLayout android:id="#+id/ll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="32dp"
android:layout_marginRight="32dp"
android:orientation="vertical"
android:background="#color/white" >
</LinearLayout>
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/white"
android:text="caca"
android:padding="32dp" />
</LinearLayout>
</ScrollView>
And finally, my keyitem_temp.xml which I'm inflating :
<?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="wrap_content"
android:background="#color/black"
android:padding="4dp"
android:orientation="horizontal" >
<TextView android:id="#+id/ind"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:textSize="18sp"
android:textColor="#color/blue" />
<TextView android:id="#+id/item"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:textSize="18sp"
android:textColor="#color/white"/>
</LinearLayout>
I have an other activity called ItemsActivity which is the same code with some little differences and it works. Any suggestion? Thanks in advance.
Try using wrap_content for all of your heights except the initial ScrollView:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/black" >
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#color/black">
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp" />
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="#string/key_items"
android:textSize="36sp"
android:textColor="#color/white" />
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="4dp" />
<LinearLayout android:id="#+id/ll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="32dp"
android:layout_marginRight="32dp"
android:orientation="vertical"
android:background="#color/white" >
</LinearLayout>
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/white"
android:text="caca"
android:padding="32dp" />
</LinearLayout>
</ScrollView>
and:
<?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="wrap_content"
android:background="#color/black"
android:padding="4dp"
android:orientation="horizontal" >
<TextView android:id="#+id/ind"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:textSize="18sp"
android:textColor="#color/blue" />
<TextView android:id="#+id/item"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:textSize="18sp"
android:textColor="#color/white"/>
</LinearLayout>
I am trying to find a way to animate changing the alpha of a FrameLayout's foreground drawable, but i cant seem to find a way of doing it.
If someone could point me in the right direction as to how i should go about this i would be hugely grateful.
The relevant code is below:
XML layout file:
<com.bacon.corey.audiotimeshift.SlidingUpPanelLayout xmlns:sothree="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
sothree:panelHeight="0dp"
sothree:shadowHeight="10dp"
sothree:paralaxOffset="100dp"
sothree:fadeColor="#android:color/transparent"
>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:padding="0dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:padding="0dip"
android:gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="0dp"
android:id="#+id/recordingListMainLayout"
android:foreground="#drawable/dim_shadow_shape_dark"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:padding="0dp"
android:gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/mainLayoutContainer"/>
<!--
<android.support.v4.view.ViewPager
android:id="#+id/viewPager"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1"
android:padding="0dp"
android:layout_margin="0dp"
/>
-->
</LinearLayout>
</FrameLayout>
<com.bacon.corey.audiotimeshift.FloatingActionsMenu
android:id="#+id/fabMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:gravity="right"
app:fab_addButtonColorNormal="#color/holo_red_light"
app:fab_addButtonColorPressed="#color/c16"
app:fab_addButtonPlusIconColor="#color/white"
app:fab_expandDirection="up"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:layout_marginEnd="10dp"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/textview_rounded_corner_background_fam"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option Four"
android:textAlignment="center"
android:padding="6dp"
android:fontFamily="sans-serif-medium"
/>
</FrameLayout>
<com.bacon.corey.audiotimeshift.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:fab_colorNormal="#color/c15"
app:fab_colorPressed="#color/c15"
app:fab_size="mini"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/textview_rounded_corner_background_fam"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option Four"
android:textAlignment="center"
android:padding="6dp"
android:fontFamily="sans-serif-medium"
/>
</FrameLayout>
<com.bacon.corey.audiotimeshift.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:fab_colorNormal="#color/c8"
app:fab_colorPressed="#color/c8"
app:fab_size="mini"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/textview_rounded_corner_background_fam"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option Four"
android:textAlignment="center"
android:padding="6dp"
android:fontFamily="sans-serif-medium"
/>
</FrameLayout>
<com.bacon.corey.audiotimeshift.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:fab_colorNormal="#color/a1"
app:fab_colorPressed="#color/a1"
app:fab_size="mini"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/textview_rounded_corner_background_fam"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option Four"
android:textAlignment="center"
android:padding="6dp"
android:fontFamily="sans-serif-medium"
/>
</FrameLayout>
<com.bacon.corey.audiotimeshift.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:fab_colorNormal="#color/a2"
app:fab_colorPressed="#color/a2"
app:fab_size="mini"
/>
</LinearLayout> </com.bacon.corey.audiotimeshift.FloatingActionsMenu>
</RelativeLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center|top"
android:textSize="16sp"
android:id="#+id/slideUpPanel"
>
</FrameLayout>
</com.bacon.corey.audiotimeshift.SlidingUpPanelLayout>
And the java code that i use to change the alpha of the foreground:
fabMain.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
boolean expanded = fabMenu.toggle();
mainActivity.getDimShadowDrop().setForeground(getResources().getDrawable(R.drawable.dim_shadow_shape_light));
mainActivity.getDimShadowDrop().getForeground().setAlpha(180);
if (expanded){
((MainActivity)getActivity()).replaceFragment(new RecordFragment(), R.id.slideUpPanel, false);
slidingUpPanelLayout.expandPanel();
defaultColor = getResources().getColor(R.color.recordDefaultColor);
}
}
});
Instead of the typical way you do it with an Animation which is from 0 to 1 you use 0 to 255. Something like this will pulse the Foreground of a CardView.
public static void pulseForeground(CardView view, long duration) {
ObjectAnimator animator = ObjectAnimator.ofInt(view.getForeground(), "alpha", 0, 255);
animator.setDuration(duration);
animator.setStartDelay(20);
animator.setRepeatMode(Animation.REVERSE);
animator.setRepeatCount(Animation.INFINITE);
animator.start();
}