dev90
dev90

Reputation: 7519

How to add Text View on Bottom of frame Layout using Java Code

I have a ViewFlipper under which i have a Linear Layout and Frame Layout.

I am adding imageViews and TextViews in Frame Layout dynamically from Java Class

Right now its displaying Text View at the top of my Activity and image View after it.

I want to it first display image View and then TextView

enter image description here

I am sharing an excerpt from my MainActivity.class

    FrameLayout newsFrameLayout;

    newsFrameLayout = (FrameLayout) findViewById(R.id.newsFrameLayout);

    FrameLayout n1= newsFrameLayout;

    ImageView imageView;


        imageView = new ImageView(this);
        n1.addView(imageView);

        titleTextView= new TextView(this);

        RelativeLayout.LayoutParams textViewParam = new RelativeLayout.LayoutParams(SlidingPaneLayout.LayoutParams.WRAP_CONTENT, SlidingPaneLayout.LayoutParams.WRAP_CONTENT);

   //   textViewParam.gravity= Gravity.BOTTOM;

        n1.addView(titleTextView,textViewParam);

Layout File

<ViewFlipper
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:id="@+id/newsSliderView"
    android:layout_alignParentTop="true"
    android:layout_alignParentStart="true">


    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/newsLinearLayout">

        <FrameLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="bottom"
            android:id="@+id/newsFrameLayout">

        </FrameLayout>

    </LinearLayout>

</ViewFlipper>

Upvotes: 1

Views: 1623

Answers (1)

Anonymous
Anonymous

Reputation: 4900

Your views are added with the default gravity which is top. You need to specify the LayoutParams with which your want the views to be added. Tο get the textview to the bottom you do this:

FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,     
FrameLayout.LayoutParams.MATCH_PARENT);
params.gravity = Gravity.BOTTOM;
titleTextView.setLayoutParams(params);
n1.addView(titleTextView);

Upvotes: 1

Related Questions