igarciama
Is there any way to create a custom element with XML that can contain a child in a specific place?
I’ve been trying to create a custom CardView with a title and below the title any type of content, but when I try overriding addView in the Kotlin class of the custom element to redirect the child it doesn’t allow it. Does anyone have any solution? Here is the code:
XML:
<?xml version="1.0" encoding="utf-8"?><LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="8dp">
<TextView
android:id="@+id/title"
style="@style/TextView.Title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="Título de ejemplo" />
<FrameLayout
android:id="@+id/childrenContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
KOTLIN:
class TarjetaTitle @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : CardView(context, attrs, defStyleAttr) {
private var title: TextView
private var childrenContainer: FrameLayout
init {
LayoutInflater.from(context).inflate(R.layout.element_tarjeta_title, this, true)
title = findViewById(R.id.title)
childrenContainer = findViewById(R.id.childrenContainer)
context.obtainStyledAttributes(attrs, R.styleable.TarjetaTitle, defStyleAttr, 0).apply {
try {
title.text = getString(R.styleable.TarjetaTitle_title)
val titleStyle = getResourceId(R.styleable.TarjetaTitle_titleStyle, -1)
if (titleStyle != -1)
title.setTextAppearance(titleStyle)
} finally {
recycle()
}
}
}
override fun addView(child: View?, params: LayoutParams?) {
childrenContainer.addView(child, params)
}
}
Popular Android topics
I want to get a clone of Instagram APK But with a difference
I want to define in this clone that, for example, it is not possible to acc...
New
Hi,
Please I need help to get DHIS2 Capture working in Android Tablet Phone desk ( KT5-3C) Android Version: 10. Build: KT5-3C_LTE05M0_K...
New
Dear Sir,
I am a beginner in Android App development and I am currently trying to establish a connection between my Android Studio Java ...
New
Hello everyone, I recently started learning Kotlin and downloaded Android Studio, but after writing my first code and trying to run it, I...
New
There is an Android app. I just want to create two GRAPHS with CPU Runtime and Battery Consumption.
It is as simple as this.
I tried w...
New
Helo,
I’m using doubleviewpager in my project:
Is there something similar that works with android x?
New
I’m stuck trying to understand how to get a variable initialised, and later updated, in kotlin to update in Jetpack Compose and cause a c...
New
Hey developers :waving_hand:
I’m currently experimenting with various mobile VPN apps to simulate different network conditions for API t...
New
My Android Studio emulator is stuck on this loading screen. What’s going on?
New
I’ve been trying to create a custom CardView with a title and below the title any type of content, but when I try overriding addView in t...
New
Other popular topics
Reading something? Working on something? Planning something? Changing jobs even!?
If you’re up for sharing, please let us know what you’...
New
Machine learning can be intimidating, with its reliance on math and algorithms that most programmers don't encounter in their regular wor...
New
Ruby, Io, Prolog, Scala, Erlang, Clojure, Haskell. With Seven Languages in Seven Weeks, by Bruce A. Tate, you’ll go beyond the syntax—and...
New
Which, if any, games do you play? On what platform?
I just bought (and completed) Minecraft Dungeons for my Nintendo Switch. Other than ...
New
You might be thinking we should just ask who’s not using VSCode :joy: however there are some new additions in the space that might give V...
New
Continuing the discussion from Thinking about learning Crystal, let’s discuss - I was wondering which languages don’t GC - maybe we can c...
New
Hello everyone! This thread is to tell you about what authors from The Pragmatic Bookshelf are writing on Medium.
New
If you get Can't find emacs in your PATH when trying to install Doom Emacs on your Mac you… just… need to install Emacs first! :lol:
bre...
New
Curious what kind of results others are getting, I think actually prefer the 7B model to the 32B model, not only is it faster but the qua...
New
Background
Lately I am in a quest to find a good quality TTS ai generation tool to run locally in order to create audio for some videos I...
New
Categories:
Sub Categories:
Popular Portals
- /elixir
- /rust
- /wasm
- /ruby
- /erlang
- /phoenix
- /keyboards
- /python
- /js
- /rails
- /security
- /go
- /swift
- /vim
- /clojure
- /java
- /emacs
- /haskell
- /svelte
- /onivim
- /typescript
- /kotlin
- /c-plus-plus
- /crystal
- /tailwind
- /react
- /gleam
- /ocaml
- /elm
- /flutter
- /vscode
- /ash
- /html
- /opensuse
- /zig
- /deepseek
- /centos
- /php
- /scala
- /react-native
- /lisp
- /textmate
- /sublime-text
- /nixos
- /debian
- /agda
- /django
- /deno
- /kubuntu
- /arch-linux
- /nodejs
- /revery
- /ubuntu
- /spring
- /manjaro
- /diversity
- /julia
- /lua
- /markdown
- /c









