Does any one know how can we send an array of images to the 'SubsamplingScaleImageView' class...
It works fine with one, but... I just want to open like 3 or 4 images and swipe between them and I just can't find a way...
Any help would be great!
Here is my (simple) code:
MainActivity:
private int[] myImages;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myImages = new int[]{
R.drawable.p01, R.drawable.p02
};
SubsamplingScaleImageView imageView = (SubsamplingScaleImageView)findViewById(R.id.imageView);
imageView.setImage(ImageSource.resource(R.drawable.p01));
}
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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=".MainActivity">
<com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</android.support.constraint.ConstraintLayout>
Thank you!
Related
Right so, I have a navbar layout. The <FrameLayout> in content_main is replaced with stand1.xml when the stand1 button in my navbar is pressed. This works without any issue.
Content_main.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"
xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior" tools:showIn="#layout/app_bar_main"
tools:context=".MainActivity">
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"></FrameLayout>
</RelativeLayout>
stand1.xml
<?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">
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/Stand1list">
</ListView>
</LinearLayout>
from main activity
if (id == R.id.Stand1) {
fm.beginTransaction().replace(R.id.content_frame, new Stand1()).commit();
setTitle(R.string.Stand1);
Following tutorials online this is my Stand1.java file which is used to populate the a list with a array of strings
public class Stand1 extends Fragment {
ListView mList;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.stand1,container,false);
mList = (ListView) root.findViewById(R.id.Stand1list);
return root;
}
public void onActivityCreated(Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);
populateListView();
}
private void populateListView() {
String[] pair = {"Pair1","Pair2","Pair3","Pair4","Pair5"};
//build adapter
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), R.layout.row_layout,pair);
mList.setAdapter(adapter);
}
}
and row_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/text1"
xmlns:android="http://schemas.android.com/apk/res/android" />
This is working, It displays the 5 strings. However i want to make it so i can also have a check box in each row.
If i try place linear layout in row_layout.xml , i get error
ArrayAdapter requires the resource ID to be a TextView
I was following stackoverflow which sorted other errors which suggested that i had to make the list at class level and inflate it in onCreate.
I know i prob have to make an custom array adapter, but my problem is how do i deal with the inflation of the view in the on create.
Im not really sure how i go about doing this. So can somebody tell me from here, how do i go about having a check box in each row.
Thanks for the help
ArrayAdapter needs to know where to put the text from your string array. By default, it assumes the layout you pass it is a TextView and will set its text to one of the strings. If you pass it a more complicated layout, you need to tell it the id of the TextView you want it to use. You can do that with this constructor.
There are a number of questions like this but the solutions haven't worked for me.
Anyways, my main activity has a button that, in its onclick method, takes me to another activity, ViewPowerActivity. I have a layout xml file for it called power_view.xml. Inside that I have some 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="wrap_content"
android:layout_marginLeft="#dimen/screen_margin"
android:layout_marginRight="#dimen/screen_margin"
android:layout_marginTop="#dimen/screen_margin"
android:orientation="vertical" >
...
ViewPowerActivity has the basic onCreateMethod:
public class ViewPowerActivity extends Activity {
private final static Powers powers=new StubPowers();
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.power_view);
Power power=powers.getPowers().get(0);
View powerView = findViewById(R.layout.power_view);
...
}
...
}
The findViewById call above is returning null.
If I remove all the code after setContentView(...) and simply return there, it displays the empty layout just fine. I've setContentView, I've cleaned the project, I've tried setting the power view as the main activity, and all sorts of things. What else could it be?
From you code it is clear thar power_view is a layout ie. xml. So R.id.power_view is incorrect.
It seems you want to access the parent view of that layout. Then do the following.
You have to set an id to the parent LinearLayout.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/parentLinear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/screen_margin"
android:layout_marginRight="#dimen/screen_margin"
android:layout_marginTop="#dimen/screen_margin"
android:orientation="vertical" >
...
Then,
View powerView = findViewById(R.id.parentLinear);
If you want to take some other view in powerView, you should set id to that view in xml layout and initialize your that view to power_view by findViewById(R.id.your_view)
power_view.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/screen_margin"
android:layout_marginRight="#dimen/screen_margin"
android:layout_marginTop="#dimen/screen_margin"
android:orientation="vertical" >
public class ViewPowerActivity extends Activity {
private final static Powers powers=new StubPowers();
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.power_view);
Power power=powers.getPowers().get(0);
View powerView = (ViewGroup)findViewById(R.id.layout);
...
}
...
}
I have to show an advertisment on the bottom of the screen using leadboltcontroller jar..I have implemented the code and I have given all the sets of permissions as well. But I am not getting any advertisment. Here is my code:
public class Leadbolt_DemoActivity extends Activity {
/** Called when the activity is first created. */
private AdController mucontroller;
private String MY_LB_SECTION_ID="328886602";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
RelativeLayout rlbottom=(RelativeLayout)findViewById(R.id.relbottom);
final Activity act = this;
rlbottom.post(new Runnable() {
public void run() {
mucontroller = new AdController(act, MY_LB_SECTION_ID);
mucontroller.setAsynchTask(true);
mucontroller.loadNotification();
mucontroller.setAdditionalDockingMargin(50);
mucontroller.loadAd();
}
//});
});
I have given one addid of another app in another machine but still i am not getting any addid..Is the addid unique for each app & for each machine???Please help me.
use Relativelayout for footer positioning of ads
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<bla.bla.AdView
android:id="#+id/ad"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#FF0000"/>
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#id/ad"/>
here is the post which you are looking for..
I have splash.png with gradient. But on screen this image looks not so good ...
My simple .apk for this question consists of:
public class TestditherActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
#Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
getWindow().setFormat(PixelFormat.RGBA_8888);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitXY"
android:src="#drawable/test"/>
</LinearLayout>
and test.xml:
<?xml version="1.0" encoding="utf-8"?>
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/splash"
android:antialias="true"
android:dither="true" />
splash.png
result
How to apply RGBA_8888 and dither correctly? Where is my mistake?
The next code gives me perfect result in emulator, but not on the real device:
public class TestditherActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
getWindow().setFormat(PixelFormat.RGBA_8888);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DITHER);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap gradient = BitmapFactory.decodeResource(getResources(), R.drawable.splash, options);
findViewById(R.id.linear).setBackgroundDrawable(new BitmapDrawable(gradient));
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linear"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
Take a look at this:
Awful background image quality in Android
Or this blog post about dithering in Android: http://android.amberfog.com/?p=247
In your case the problem is in the bitmap xml. I remember reading somewhere that the dither only works if the bitmap has a tileMode set.
Many of you know, that there's is a class RealViewSwticher created by Marc Reichelt http://marcreichelt.blogspot.com/2010_09_01_archive.html
If someone used or uses this thing, please can you help me.
Here's my .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"
>
<de.marcreichelt.android.RealViewSwitcher
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/real_view_switcher">
<GridView android:id="#+id/gridView1" android:layout_width="match_parent" android:layout_height="match_parent"></GridView>
<GridView android:id="#+id/gridView2" android:layout_width="match_parent" android:layout_height="match_parent"></GridView>
</de.marcreichelt.android.RealViewSwitcher>
</LinearLayout>
And here's my main class.
public class MyMain extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
RealViewSwitcher realViewSwitcher = (RealViewSwitcher)findViewById(R.id.real_view_switcher);
GridView gridview = (GridView) findViewById(R.id.gridView1);
GridView gridview2 = (GridView) findViewById(R.id.gridView2);
gridview.setAdapter(new ImageAdapter(this));
gridview2.setAdapter(new ImageAdapter(this));
realViewSwitcher.setOnScreenSwitchListener(onScreenSwitchListener);
}
private final RealViewSwitcher.OnScreenSwitchListener onScreenSwitchListener = new RealViewSwitcher.OnScreenSwitchListener() {
#Override
public void onScreenSwitched(int screen) {
// this method is executed if a screen has been activated, i.e. the screen is completely visible
// and the animation has stopped (might be useful for removing / adding new views)
Log.d("RealViewSwitcher", "switched to screen: " + screen);
}
};
}
I really don't understand what i am doing wrong, in the Example there's comment how to use it in xml:
// note that you can also define your own views directly in a resource XML, too by using:
// <de.marcreichelt.android.RealViewSwitcher
// android:layout_width="fill_parent"
// android:layout_height="fill_parent"
// android:id="#+id/real_view_switcher">
// <!-- your views here -->
// </de.marcreichelt.android.RealViewSwitcher>
The problem is: It is not working. I can see only my main GridView and i can't scroll to the second. If soemeone knews how where i made a mistake or if someone knews another way to do a real scrolling between views, please answer this.
why don't you use ScrollView? Try to use something like this:
<ScrollView android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="110px">
<LinearLayout
android:id="#+id/grds"
android:drawingCacheQuality="low"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<GridView android:id="#+id/gridView1" android:layout_width="match_parent" android:layout_height="match_parent"></GridView>
<GridView android:id="#+id/gridView2" android:layout_width="match_parent" android:layout_height="match_parent"></GridView>
</LinearLayout>
</ScrollView>
if it does't work, looak at this post
Switching between two GridViews in the same Activity