I've implemented a LinearLayout with a tall/narrow image on the left side (top to bottom) and a HorizontalScrollView
on the right side for showing a long image.
The problem is that I have not managed to handle the HorizontalScrollView
properly. It does not show the left part of the image (I am unable to scroll in that direction), and it is possible to scroll far beyond the image borders on the other side...
I have tried different types of wrapping for the image and the HorizontalScrollView
, but the problem is always the same.
Additionally, I have trouble with the left image; the wrapping does not work so there's white space on both sides of it.
This is hard to explain, so I will instead give you some example code that presents the problem:
XML file (I've made many versions of it but always having the same problem):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:adjustViewBounds="true"
android:orientation="horizontal" >
<LinearLayout
android:id="@+id/leftContainer"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:adjustViewBounds="true"
android:orientation="horizontal" >
<ImageView
android:id="@+id/ivExampleBar"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:contentDescription="Bar on the left side"
android:src="@drawable/examplebar" />
</LinearLayout>
<HorizontalScrollView
android:id="@+id/hscroll"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="left"
android:scrollbarFadeDuration="0">
<LinearLayout
android:id="@+id/container"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:orientation="horizontal" >
<ImageView
android:id="@+id/ivExampleImg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:contentDescription="Big scrollable image"
android:src="@drawable/exampleimg"
/>
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
Java file (I've tried ScrollTo in order to show also the left part of the image, but it works only on a specific resolution/phone...):
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
public class TestActivity extends Activity {
//private LinearLayout scrollContainer;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// FULL SCREEN
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
this.setContentView(R.layout.testlayout);
//scrollContainer = (LinearLayout) findViewById(R.id.container);
//scrollContainer.scrollTo(-195, 0);
}
@Override
protected void onPause(){
super.onPause();
finish();
}
}
Do you have any help on these problems?
- make the HorizontalScrollView wrap my image so there's no white space around it
- make it possible to scroll all the way to the borders of the image
- avoid the white space around the left image