<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:measureAllChildren="true"
android:overScrollMode="ifContentScrolls" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/viewPagerLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
contents like button textview are here
</FrameLayout>
<FrameLayout
android:id="#+id/viewPagerLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
contents like button textview are here
</FrameLayout>
</LinearLayout>
</Scrollview>
While KeyBoard popup the scrollview is not scrolled as we think ...
Related
I have a problem to include a ScrollView with a ConstraintLayout. How Can I mix the two? I would like to get a good resizing of the screen, but with the capability by scrolling the screen if the number of the buttons will increase.
I tried this, but without success. I used that ticket
here is the xml file:
<ScrollView
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"
android:fillViewport="true">
<androidx.constraintlayout.widget.ConstraintLayout
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:id="#+id/homeContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/imagealliance"
android:backgroundTint="#80FFFFFF"
android:backgroundTintMode="src_over"
android:gravity="center"
android:theme="#style/AppTheme"
tools:context=".LoginActivity">
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:alpha="0.6"
android:scaleType="fitXY"
android:src="#drawable/logoalliance"
app:layout_constraintBottom_toTopOf="#+id/txt_login"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
Here is the code for the buttons:
public class HomeFragment extends Fragment {
...
layout.addView(eventBtn);
if (i == 0)
{
test1 = eventBtn.getId();
Log.d("test1", String.valueOf(eventBtn.getId()));
}
if (i == countUser.length() - 1)
{
test2 = eventBtn.getId();
Log.d("test2", String.valueOf(eventBtn.getId()));
}
Here is the code for the layout:
// Create ConstraintSet
ConstraintSet constraintSet = new ConstraintSet();
// Make sure all previous Constraints from ConstraintLayout are not lost
constraintSet.clone(layout2);
// Create Rule that states that the START of btn_contact_us1 will be positioned at the END of btn_contact_us2
constraintSet.connect(imageView1.getId(), ConstraintSet.START, test1, ConstraintSet.END);
constraintSet.applyTo(layout2);
Thanks in advance
Try updating your xml by following code
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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=".MainActivityStack">
<ScrollView
android:layout_width="0dp"
android:layout_height="0dp"
android:fillViewport="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:alpha="0.6"
android:scaleType="fitXY"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
im' doing some exercice to learn android progamming.
I want that every button in this horizontal layout is full widht.
So user can scroll it.
Here is my xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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">
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="140dp">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Button1" />
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0"
android:text="Button2" />
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Button3" />
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Button4" />
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Button5" />
</LinearLayout>
</HorizontalScrollView>
</android.support.constraint.ConstraintLayout>
So button 1, and every other button have to scroll line in a gallery
You are using HorizontalScrollView so match_parent for width won't work.
You have to set the width of button programmatically to the width of screen width.
Try this
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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">
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="140dp">
<LinearLayout
android:id="#+id/ll"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Button1" />
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Button2" />
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Button3" />
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Button4" />
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Button5" />
</LinearLayout>
</HorizontalScrollView>
</android.support.constraint.ConstraintLayout>
MainActivity.java
public class MainActivity extends AppCompatActivity {
private LinearLayout linearLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
linearLayout=findViewById(R.id.ll);
int width=getScreenWidth(Main2Activity.this);
int childCount=linearLayout.getChildCount();
for (int i=0;i<childCount;i++){
Button button= (Button) linearLayout.getChildAt(i);
button.setWidth(width);
}
}
public static int getScreenWidth(Context context) {
WindowManager windowManager = (WindowManager) context
.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics dm = new DisplayMetrics();
windowManager.getDefaultDisplay().getMetrics(dm);
return dm.widthPixels;
} }
What I am trying to do is to create three tabs in my main xml file. and then load up the fragments based on the tabs which has been pressed.
I have having problems with the Fragment Tab Host. I have this XML which has ;
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="#369742"
android:gravity="start|end"
android:longClickable="true">
<FragmentTabHost
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/tabHost"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:clickable="false">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:clickable="false"
android:background="#5DAD68">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:clickable="false"
android:background="#5DAD68"
android:weightSum="1">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="270dp"
android:layout_height="wrap_content"
android:background="#5DAD68"
android:clickable="false"
android:measureWithLargestChild="true"
android:orientation="horizontal"
android:layout_weight="1.04"
android:longClickable="false"
android:paddingTop="10dp"
android:paddingLeft="30dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"></TabWidget>
<ImageButton
android:layout_width="62dp"
android:layout_height="40dp"
android:id="#+id/horsePointer"
android:backgroundTintMode="src_atop"
android:src="#drawable/ic_horse"
android:layout_toRightOf="#android:id/tabs"
android:background="#5DAD68"
android:layout_gravity="center_vertical" />
</LinearLayout>
<FrameLayout
android:id="#+id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="false">
<LinearLayout
android:id="#+id/tab2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:clickable="false"
android:background="#FFFFFF"
android:weightSum="1">
</LinearLayout>
<LinearLayout
android:id="#+id/tab1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:clickable="true"
android:weightSum="1"
android:background="#FFFFFF"
android:layout_gravity="bottom">
</LinearLayout>
<LinearLayout
android:id="#+id/tab3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:clickable="false"
android:background="#FFFFFF">
</LinearLayout>
</FrameLayout>
</LinearLayout>
</FragmentTabHost>
In My Main activity I have got this code ;
public class MainActivity extends ActionBarActivity {
private FragmentTabHost tabHost;
private TextView click;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home_tab_main);
// Refactor at your will.
tabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
tabHost.setup(this, getSupportFragmentManager(), R.id.tabcontent);
tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("", getResources().getDrawable(R.drawable.ic_tab1)),
tab1Fragment.class, null);
tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("", getResources().getDrawable(R.drawable.tab2)),
tab2Fragment.class, null);
tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator("", getResources().getDrawable(R.drawable.ic_tab3)),
tab3Fragment.class, null);
}
When I run this program it says "Unfortunately, Example Project has stopped."
This is the Logcat I get ;
Logcat
You have used a TabHost in your XML layout and a FragmentTabHost in your Activity code. The two classes are different, and you can use only one of them at a time, not both together.
Your XML layout needs to be defined like this:
<android.support.v4.app.FragmentTabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"/>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
i want make fixed footer, but I've got a problem.
My activity_main:
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/swiperefresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.shppandroid1.app.MainActivity">
<ListView
android:id="#+id/listView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ececec"
android:divider="#null"
android:dividerHeight="0dp"/>
</android.support.v4.widget.SwipeRefreshLayout>
If I add here LinearLayout, the app just shows the error. How can I make fixed footer?
Example: http://blog.maxaller.name/wp-content/uploads/2010/05/listview_footer_scrolling.png -> Button "Add Item" - it fixed footer.
Finally i got it.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="#0A756E"
android:gravity="center" >
<LinearLayout
android:id="#+id/ll_archiv"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/tv_archiv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="#string/archiv"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#fff" />
</LinearLayout>
</RelativeLayout>
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/footer"
android:layout_alignParentTop="true" >
</ListView>
</android.support.v4.widget.SwipeRefreshLayout>
Inside of your code, u have to set the height of the footer as a padding for the listview. Because this is in px and u'll need dp, just transform it:
float scale = getResources().getDisplayMetrics().density;
int size = (int) (FOOTERHEIGHT * scale + 0.5f);
SWIPEREFRESHLAYOUT.setPadding(0, 0, 0, size);
I am adding views dynamically like this:
LayoutInflater layoutInflater =
(LayoutInflater) getActivity().getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View addView = layoutInflater.inflate(R.layout.dynamicabout, null);
TextView textOut = (TextView)addView.findViewById(R.id.aboutcontent);
textOut.setText(strings.get(index));
((ViewGroup) v).addView(addView);
However, once we get to the bottom of the screen and beyond, there's no scrollbar.
I tried using the ScrollView, but that doesn't do anything.
dynamicabout.xml
<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="wrap_content">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/aboutcontent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="all"/>
</LinearLayout>
</ScrollView>
</RelativeLayout>
about.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="#dimen/stdpadding"
android:paddingRight="#dimen/stdpadding"
android:paddingBottom="#dimen/stdpadding"
android:paddingTop="#dimen/stdpadding"
android:orientation="vertical" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ScrollView>
</LinearLayout>
What you need to do is you need to have Parent and Child view. Add child to the Parent. Parent is LinearLayout in ScrollView in dynamicabout.xml. Child is about XML. Inflate about XML on the runtime and Add it into Parent View (LinearLayout in ScrollView).
P.S. > Set an ID for the Parent Layout in order to be able to add views inside it, as far as I see it doesn't have ID.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="#dimen/stdpadding"
android:paddingRight="#dimen/stdpadding"
android:paddingBottom="#dimen/stdpadding"
android:paddingTop="#dimen/stdpadding"
android:orientation="vertical" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/linear
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ScrollView>
</LinearLayout>
////////////////////////////////////////////////
<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="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/aboutcontent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="all"/>
</LinearLayout>
</RelativeLayout>
//////////////////////////////////////////////////////////////
LinearLayout linear=(LinearLayout)findviewbyId(R.id.linear);
LayoutInflater layoutInflater =
(LayoutInflater) getActivity().getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View addView = layoutInflater.inflate(R.layout.dynamicabout, null);
TextView textOut = (TextView)addView.findViewById(R.id.aboutcontent);
textOut.setText(strings.get(index));
linearview.addView(addView);
please chk this code: